From: Nurzhan Muratkhan Date: Mon, 23 Feb 2026 19:54:55 +0500 Subject: Ensure compatibility with Go 1.27 and encoding/json/v2 Fix test failures occurring with Go 1.27: - In TestNewRequest_invalidJSON, use an unencodable function field instead of map[interface{}]interface{} and avoid asserting UnsupportedTypeError. - In TestHookDelivery_ParsePayload_invalidPayload and TestSecurityAdvisoriesService_ListRepositorySecurityAdvisories*, relax unmarshal error string checks to account for Go 1.27's updated struct field path format in unmarshal errors. [Backport divergence note: adapted error assertion checks to keep context.Background() rather than t.Context() which was introduced in later Go releases.] Origin: backport, https://github.com/google/go-github/commit/92a3830f9be93a0a314c4d6c2726ee820cc79c2e Bug-Debian: https://bugs.debian.org/1146199 Closes: #1146199 Forwarded: not-needed --- github/github_test.go | 5 +---- github/repos_hooks_deliveries_test.go | 3 ++- github/security_advisories_test.go | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/github/github_test.go b/github/github_test.go index 9a369a2..61b33fc 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -539,16 +539,13 @@ func TestNewRequest_invalidJSON(t *testing.T) { c := NewClient(nil) type T struct { - A map[interface{}]interface{} + F func() } _, err := c.NewRequest("GET", ".", &T{}) if err == nil { t.Error("Expected error to be returned.") } - if err, ok := err.(*json.UnsupportedTypeError); !ok { - t.Errorf("Expected a JSON error; got %#v.", err) - } } func TestNewRequest_badURL(t *testing.T) { diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 057d712..ba5a3f0 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -11,6 +11,7 @@ import ( "fmt" "net/http" "reflect" + "strings" "testing" "github.com/google/go-cmp/cmp" @@ -261,7 +262,7 @@ func TestHookDelivery_ParsePayload_invalidPayload(t *testing.T) { } _, err := d.ParseRequestPayload() - if err == nil || err.Error() != "json: cannot unmarshal string into Go struct field CheckRun.check_run.id of type int64" { + if err == nil || !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "check_run.id") { t.Errorf("unexpected error: %v", err) } } diff --git a/github/security_advisories_test.go b/github/security_advisories_test.go index b43ef7f..9d4c975 100644 --- a/github/security_advisories_test.go +++ b/github/security_advisories_test.go @@ -589,8 +589,8 @@ func TestSecurityAdvisoriesService_ListRepositorySecurityAdvisoriesForOrg_Unmars ctx := context.Background() advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisoriesForOrg(ctx, "o", nil) if err == nil { - t.Errorf("Expected unmarshal error") - } else if !strings.Contains(err.Error(), "json: cannot unmarshal number into Go struct field SecurityAdvisory.ghsa_id of type string") { + t.Error("Expected unmarshal error") + } else if !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "ghsa_id") { t.Errorf("ListRepositorySecurityAdvisoriesForOrg returned unexpected error: %v", err) } if got, want := resp.Response.StatusCode, http.StatusOK; got != want { @@ -720,8 +720,8 @@ func TestSecurityAdvisoriesService_ListRepositorySecurityAdvisories_UnmarshalErr ctx := context.Background() advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisories(ctx, "o", "r", nil) if err == nil { - t.Errorf("Expected unmarshal error") - } else if !strings.Contains(err.Error(), "json: cannot unmarshal number into Go struct field SecurityAdvisory.ghsa_id of type string") { + t.Error("Expected unmarshal error") + } else if !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "ghsa_id") { t.Errorf("ListRepositorySecurityAdvisories returned unexpected error: %v", err) } if got, want := resp.Response.StatusCode, http.StatusOK; got != want {