mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
add more unit testing case
This commit is contained in:
@ -1,28 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/encoding/gparser"
|
||||
)
|
||||
import "github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
type User struct {
|
||||
Name string `xml:"name" json:"name"`
|
||||
Age int `xml:"bb" json:"dd" gconv:"aa"`
|
||||
Addr string `xml:"cc"`
|
||||
func Test() {
|
||||
gdebug.PrintStack()
|
||||
}
|
||||
|
||||
func main() {
|
||||
user := User{
|
||||
Name: "sss",
|
||||
Age: 22,
|
||||
Addr: "kaldsj",
|
||||
}
|
||||
|
||||
xmlStr, err := gparser.VarToXmlIndent(user, "user")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(string(xmlStr))
|
||||
Test()
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func Test_Router_Basic(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// 测试HTTP Method注册.
|
||||
// HTTP method register.
|
||||
func Test_Router_Method(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
@ -92,7 +92,32 @@ func Test_Router_Method(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// 测试状态返回.
|
||||
// Extra char '/' of the router.
|
||||
func Test_Router_ExtraChar(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/api", func(group *ghttp.RouterGroup) {
|
||||
group.GET("/test", func(r *ghttp.Request) {
|
||||
r.Response.Write("test")
|
||||
})
|
||||
})
|
||||
s.SetPort(p)
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.Case(t, func() {
|
||||
client := ghttp.NewClient()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
gtest.Assert(client.GetContent("/api/test"), "test")
|
||||
gtest.Assert(client.GetContent("/api/test/"), "test")
|
||||
gtest.Assert(client.GetContent("/api/test//"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
// Custom status handler.
|
||||
func Test_Router_Status(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
@ -145,7 +170,6 @@ func Test_Router_Status(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// 自定义状态码处理.
|
||||
func Test_Router_CustomStatusHandler(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
@ -174,7 +198,7 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// 测试不存在的路由.
|
||||
// 404 not found router.
|
||||
func Test_Router_404(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
|
||||
Reference in New Issue
Block a user