Go checkEqualJSON()

1 개요[ | ]

Go checkEqualJSON()
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 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}