Skip to content

Commit a697201

Browse files
authored
chore: Fix TestNewFormRequest (#4043)
1 parent 5f68d54 commit a697201

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

github/github_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,23 @@ func TestNewFormRequest(t *testing.T) {
661661
form := url.Values{}
662662
form.Add("login", "l")
663663
inBody, outBody := strings.NewReader(form.Encode()), "login=l"
664-
req, _ := c.NewFormRequest(inURL, inBody)
664+
req, err := c.NewFormRequest(inURL, inBody)
665+
if err != nil {
666+
t.Fatalf("NewFormRequest returned unexpected error: %v", err)
667+
}
665668

666669
// test that relative URL was expanded
667670
if got, want := req.URL.String(), outURL; got != want {
668671
t.Errorf("NewFormRequest(%q) URL is %v, want %v", inURL, got, want)
669672
}
670673

671674
// test that body was form encoded
672-
body, _ := io.ReadAll(req.Body)
675+
body, err := io.ReadAll(req.Body)
676+
if err != nil {
677+
t.Fatalf("Error reading request body: %v", err)
678+
}
673679
if got, want := string(body), outBody; got != want {
674-
t.Errorf("NewFormRequest(%q) Body is %v, want %v", inBody, got, want)
680+
t.Errorf("NewFormRequest() Body is %v, want %v", got, want)
675681
}
676682

677683
// test that default user-agent is attached to the request
@@ -681,13 +687,16 @@ func TestNewFormRequest(t *testing.T) {
681687

682688
apiVersion := req.Header.Get(headerAPIVersion)
683689
if got, want := apiVersion, defaultAPIVersion; got != want {
684-
t.Errorf("NewRequest() %v header is %v, want %v", headerAPIVersion, got, want)
690+
t.Errorf("NewFormRequest() %v header is %v, want %v", headerAPIVersion, got, want)
685691
}
686692

687-
req, _ = c.NewFormRequest(inURL, inBody, WithVersion("2022-11-29"))
693+
req, err = c.NewFormRequest(inURL, inBody, WithVersion("2022-11-29"))
694+
if err != nil {
695+
t.Fatalf("NewFormRequest with WithVersion returned unexpected error: %v", err)
696+
}
688697
apiVersion = req.Header.Get(headerAPIVersion)
689698
if got, want := apiVersion, "2022-11-29"; got != want {
690-
t.Errorf("NewRequest() %v header is %v, want %v", headerAPIVersion, got, want)
699+
t.Errorf("NewFormRequest() %v header is %v, want %v", headerAPIVersion, got, want)
691700
}
692701
}
693702

0 commit comments

Comments
 (0)