Skip to content

Commit 92a3830

Browse files
authored
feat: Ensure compatibility with encoding/json/v2 experiment (#4029)
1 parent c02c318 commit 92a3830

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

github/github_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,13 @@ func TestNewRequest_invalidJSON(t *testing.T) {
572572
c := NewClient(nil)
573573

574574
type T struct {
575-
A map[any]any
575+
F func()
576576
}
577577
_, err := c.NewRequest("GET", ".", &T{})
578578

579579
if err == nil {
580580
t.Error("Expected error to be returned.")
581581
}
582-
if !errors.As(err, new(*json.UnsupportedTypeError)) {
583-
t.Errorf("Expected a JSON error; got %#v.", err)
584-
}
585582
}
586583

587584
func TestNewRequest_badURL(t *testing.T) {

github/repos_hooks_deliveries_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"net/http"
12+
"strings"
1213
"testing"
1314

1415
"github.com/google/go-cmp/cmp"
@@ -261,7 +262,7 @@ func TestHookDelivery_ParsePayload_invalidPayload(t *testing.T) {
261262
}
262263

263264
_, err := d.ParseRequestPayload()
264-
if err == nil || err.Error() != "json: cannot unmarshal string into Go struct field CheckRun.check_run.id of type int64" {
265+
if err == nil || !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "check_run.id") {
265266
t.Errorf("unexpected error: %v", err)
266267
}
267268
}

github/security_advisories_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func TestSecurityAdvisoriesService_ListRepositorySecurityAdvisoriesForOrg_Unmars
590590
advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisoriesForOrg(ctx, "o", nil)
591591
if err == nil {
592592
t.Error("Expected unmarshal error")
593-
} else if !strings.Contains(err.Error(), "json: cannot unmarshal number into Go struct field SecurityAdvisory.ghsa_id of type string") {
593+
} else if !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "ghsa_id") {
594594
t.Errorf("ListRepositorySecurityAdvisoriesForOrg returned unexpected error: %v", err)
595595
}
596596
if got, want := resp.Response.StatusCode, http.StatusOK; got != want {
@@ -721,7 +721,7 @@ func TestSecurityAdvisoriesService_ListRepositorySecurityAdvisories_UnmarshalErr
721721
advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisories(ctx, "o", "r", nil)
722722
if err == nil {
723723
t.Error("Expected unmarshal error")
724-
} else if !strings.Contains(err.Error(), "json: cannot unmarshal number into Go struct field SecurityAdvisory.ghsa_id of type string") {
724+
} else if !strings.Contains(err.Error(), "json: cannot unmarshal") || !strings.Contains(err.Error(), "ghsa_id") {
725725
t.Errorf("ListRepositorySecurityAdvisories returned unexpected error: %v", err)
726726
}
727727
if got, want := resp.Response.StatusCode, http.StatusOK; got != want {

0 commit comments

Comments
 (0)