httpexpect
httpexpect copied to clipboard
Add a key to the fail message report
What am I using?
- Web framework: Gin
- Ide: vscode
Go version
go 1.16+
Repositorie
https://github.com/snowlyg/iris-admin
When I use https://github.com/snowlyg/httptest to test HTTP API and the HTTP response object or array data, I can't know the fail is which key.
func (rks ResponseKeys) Test(object *httpexpect.Object) {
for _, rk := range rks {
zap_server.ZAPLOG.Info(rk.Key)
// to sign the test data key name
if rk.Value == nil {
continue
}
switch reflect.TypeOf(rk.Value).String() {
case "string":
if strings.ToLower(rk.Type) == "notempty" {
object.Value(rk.Key).String().NotEmpty()
} else {
object.Value(rk.Key).String().Equal(rk.Value.(string))
}
case "float64":
if strings.ToLower(rk.Type) == "ge" {
object.Value(rk.Key).Number().Ge(rk.Value.(float64))
} else {
object.Value(rk.Key).Number().Equal(rk.Value.(float64))
}
case "uint":
if strings.ToLower(rk.Type) == "ge" {
object.Value(rk.Key).Number().Ge(rk.Value.(uint))
} else {
object.Value(rk.Key).Number().Equal(rk.Value.(uint))
}
case "int":
if strings.ToLower(rk.Type) == "ge" {
object.Value(rk.Key).Number().Ge(rk.Value.(int))
} else {
object.Value(rk.Key).Number().Equal(rk.Value.(int))
}
case "[]base.ResponseKeys":
if strings.ToLower(rk.Type) == "empty" {
object.Value(rk.Key).Array().Empty()
continue
}
I will #add a key to the fail message report like below :