Skip to content

Commit 0316b73

Browse files
committed
More unit tests
1 parent 4194adc commit 0316b73

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

context_test.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ func TestContextReset(t *testing.T) {
7777
assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)
7878
}
7979

80+
func TestContextHandlers(t *testing.T) {
81+
c, _, _ := createTestContext()
82+
assert.Nil(t, c.handlers)
83+
assert.Nil(t, c.handlers.Last())
84+
85+
c.handlers = HandlersChain{}
86+
assert.NotNil(t, c.handlers)
87+
assert.Nil(t, c.handlers.Last())
88+
89+
f := func(c *Context) {}
90+
g := func(c *Context) {}
91+
92+
c.handlers = HandlersChain{f}
93+
compareFunc(t, f, c.handlers.Last())
94+
95+
c.handlers = HandlersChain{f, g}
96+
compareFunc(t, g, c.handlers.Last())
97+
}
98+
8099
// TestContextSetGet tests that a parameter is set correctly on the
81100
// current context and can be retrieved using Get.
82101
func TestContextSetGet(t *testing.T) {
@@ -190,13 +209,13 @@ func TestContextQueryAndPostForm(t *testing.T) {
190209

191210
var obj struct {
192211
Foo string `form:"foo"`
193-
Id string `form:"id"`
212+
ID string `form:"id"`
194213
Page string `form:"page"`
195214
Both string `form:"both"`
196215
}
197216
assert.NoError(t, c.Bind(&obj))
198217
assert.Equal(t, obj.Foo, "bar")
199-
assert.Equal(t, obj.Id, "main")
218+
assert.Equal(t, obj.ID, "main")
200219
assert.Equal(t, obj.Page, "11")
201220
assert.Equal(t, obj.Both, "POST")
202221
}

errors_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func TestErrorSlice(t *testing.T) {
6363
{Err: errors.New("third"), Type: ErrorTypePublic, Meta: H{"status": "400"}},
6464
}
6565

66+
assert.Equal(t, errs, errs.ByType(ErrorTypeAny))
6667
assert.Equal(t, errs.Last().Error(), "third")
6768
assert.Equal(t, errs.Errors(), []string{"first", "second", "third"})
6869
assert.Equal(t, errs.ByType(ErrorTypePublic).Errors(), []string{"third"})

fs.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ type (
1414
}
1515
)
1616

17-
// It returns a http.Filesystem that can be used by http.FileServer(). It is used interally
17+
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used interally
1818
// in router.Static().
1919
// if listDirectory == true, then it works the same as http.Dir() otherwise it returns
2020
// a filesystem that prevents http.FileServer() to list the directory files.
2121
func Dir(root string, listDirectory bool) http.FileSystem {
2222
fs := http.Dir(root)
2323
if listDirectory {
2424
return fs
25-
} else {
26-
return &onlyfilesFS{fs}
2725
}
26+
return &onlyfilesFS{fs}
2827
}
2928

3029
// Conforms to http.Filesystem

0 commit comments

Comments
 (0)