1 개요[ | ]
- Go checkEqualJSON()
Go
Copy
func checkEqualJSON(t *testing.T, want string, got interface{}, extras ...interface{}) {
if reflect.TypeOf(got).String() == "*errors.errorString" {
got = fmt.Sprintf("%s", got)
}
extraMessage := ""
for _, extra := range extras {
if extra != nil {
extraMessage += fmt.Sprintf("%v", extra)
}
}
temp, err := json.Marshal(got)
_, file, line, _ := runtime.Caller(1)
t.Logf("%s:%d: %s\n", filepath.Base(file), line, extraMessage)
if err != nil {
t.Fatalf("%s:%d: %s\ncannot marshal to json from got=[%v]", filepath.Base(file), line, extraMessage, got)
}
gotJSONString := string(temp)
if strings.Compare(gotJSONString, want) != 0 {
t.Fatalf("%s:%d: %s\nwant == `%v`\ngot === `%s`", filepath.Base(file), line, extraMessage, want, gotJSONString)
}
}
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.