瀏覽代碼

More unit tests

Manu Mtz-Almeida 10 年之前
父節點
當前提交
0316b735c4
共有 3 個文件被更改,包括 24 次插入5 次删除
  1. 21 2
      context_test.go
  2. 1 0
      errors_test.go
  3. 2 3
      fs.go

+ 21 - 2
context_test.go

@@ -77,6 +77,25 @@ func TestContextReset(t *testing.T) {
 	assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)
 }
 
+func TestContextHandlers(t *testing.T) {
+	c, _, _ := createTestContext()
+	assert.Nil(t, c.handlers)
+	assert.Nil(t, c.handlers.Last())
+
+	c.handlers = HandlersChain{}
+	assert.NotNil(t, c.handlers)
+	assert.Nil(t, c.handlers.Last())
+
+	f := func(c *Context) {}
+	g := func(c *Context) {}
+
+	c.handlers = HandlersChain{f}
+	compareFunc(t, f, c.handlers.Last())
+
+	c.handlers = HandlersChain{f, g}
+	compareFunc(t, g, c.handlers.Last())
+}
+
 // TestContextSetGet tests that a parameter is set correctly on the
 // current context and can be retrieved using Get.
 func TestContextSetGet(t *testing.T) {
@@ -190,13 +209,13 @@ func TestContextQueryAndPostForm(t *testing.T) {
 
 	var obj struct {
 		Foo  string `form:"foo"`
-		Id   string `form:"id"`
+		ID   string `form:"id"`
 		Page string `form:"page"`
 		Both string `form:"both"`
 	}
 	assert.NoError(t, c.Bind(&obj))
 	assert.Equal(t, obj.Foo, "bar")
-	assert.Equal(t, obj.Id, "main")
+	assert.Equal(t, obj.ID, "main")
 	assert.Equal(t, obj.Page, "11")
 	assert.Equal(t, obj.Both, "POST")
 }

+ 1 - 0
errors_test.go

@@ -63,6 +63,7 @@ func TestErrorSlice(t *testing.T) {
 		{Err: errors.New("third"), Type: ErrorTypePublic, Meta: H{"status": "400"}},
 	}
 
+	assert.Equal(t, errs, errs.ByType(ErrorTypeAny))
 	assert.Equal(t, errs.Last().Error(), "third")
 	assert.Equal(t, errs.Errors(), []string{"first", "second", "third"})
 	assert.Equal(t, errs.ByType(ErrorTypePublic).Errors(), []string{"third"})

+ 2 - 3
fs.go

@@ -14,7 +14,7 @@ type (
 	}
 )
 
-// It returns a http.Filesystem that can be used by http.FileServer(). It is used interally
+// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used interally
 // in router.Static().
 // if listDirectory == true, then it works the same as http.Dir() otherwise it returns
 // a filesystem that prevents http.FileServer() to list the directory files.
@@ -22,9 +22,8 @@ func Dir(root string, listDirectory bool) http.FileSystem {
 	fs := http.Dir(root)
 	if listDirectory {
 		return fs
-	} else {
-		return &onlyfilesFS{fs}
 	}
+	return &onlyfilesFS{fs}
 }
 
 // Conforms to http.Filesystem