From 9ac7a84eb53eef2fcdf70898568aec50770184fb Mon Sep 17 00:00:00 2001 From: Haihan Jiang Date: Mon, 25 May 2026 23:33:06 -0700 Subject: [PATCH] test: Cover CodeResult JSON marshaling --- github/search_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/github/search_test.go b/github/search_test.go index fc30fc75ebe..b335724090b 100644 --- a/github/search_test.go +++ b/github/search_test.go @@ -1069,6 +1069,39 @@ func TestUsersSearchResult_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } +func TestCodeResult_Marshal(t *testing.T) { + t.Parallel() + testJSONMarshal(t, &CodeResult{}, "{}") + + u := &CodeResult{ + Name: Ptr("main.go"), + Path: Ptr("cmd/main.go"), + SHA: Ptr("abc123"), + HTMLURL: Ptr("https://github.com/o/r/blob/main/cmd/main.go"), + Repository: &Repository{ID: Ptr(int64(1))}, + TextMatches: []*TextMatch{ + {ObjectURL: Ptr("https://api.github.com/search/code")}, + }, + } + + want := `{ + "name": "main.go", + "path": "cmd/main.go", + "sha": "abc123", + "html_url": "https://github.com/o/r/blob/main/cmd/main.go", + "repository": { + "id": 1 + }, + "text_matches": [ + { + "object_url": "https://api.github.com/search/code" + } + ] + }` + + testJSONMarshal(t, u, want) +} + func TestCodeSearchResult_Marshal(t *testing.T) { t.Parallel() testJSONMarshal(t, &CodeSearchResult{}, "{}")