chore: add more tests (#3018)

This commit is contained in:
Kevin Wan
2023-03-12 20:42:50 +08:00
committed by GitHub
parent 3e093bf34e
commit 60a13f1e53
8 changed files with 107 additions and 39 deletions

View File

@@ -28,7 +28,8 @@ func TestNewServer(t *testing.T) {
const configYaml = `
Name: foo
Port: 54321
Host: localhost
Port: 0
`
var cnf RestConf
assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
@@ -101,6 +102,23 @@ Port: 54321
svr.Start()
svr.Stop()
}()
func() {
defer func() {
p := recover()
switch v := p.(type) {
case error:
assert.Equal(t, "foo", v.Error())
default:
t.Fail()
}
}()
svr.StartWithOpts(func(svr *http.Server) {
svr.RegisterOnShutdown(func() {})
})
svr.Stop()
}()
}
}
@@ -569,7 +587,6 @@ Port: 54321
Method: http.MethodGet,
Path: "/user/:name",
Handler: func(writer http.ResponseWriter, request *http.Request) {
var userInfo struct {
Name string `path:"name"`
}