Go checkEqualJSON()

Jmnote (토론 | 기여)님의 2022년 5월 23일 (월) 13:19 판 (새 문서: ==개요== ;Go checkEqualJSON() <syntaxhighlight lang='go'> func checkEqualJSON(t *testing.T, want string, got interface{}, messages ...string) { if reflect.TypeOf(got).String() ==...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Go checkEqualJSON()
func checkEqualJSON(t *testing.T, want string, got interface{}, messages ...string) {
	if reflect.TypeOf(got).String() == "*errors.errorString" {
		got = fmt.Sprintf("%s", got)
	}
	temp, err := json.Marshal(got)
	if err != nil {
		t.Fatalf("cannot marshal to json from got=[%v]", got)
	}
	gotJSONString := string(temp)
	if strings.Compare(gotJSONString, want) != 0 {
		t.Fatalf("\n== want : `%v`\n== got : `%s`", want, gotJSONString)
		if len(messages) > 0 {
			for message := range messages {
				t.Log(message)
			}
		}
	}
}

2 같이 보기

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