MCPcopy Index your code
hub / github.com/google/go-github / TestNewFormRequest

Function TestNewFormRequest

github/github_test.go:1758–1803  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1756}
1757
1758func TestNewFormRequest(t *testing.T) {
1759 t.Parallel()
1760 c := mustNewClient(t)
1761
1762 inURL, outURL := "/foo", defaultBaseURL+"foo"
1763 form := url.Values{}
1764 form.Add("login", "l")
1765 inBody, outBody := strings.NewReader(form.Encode()), "login=l"
1766 req, err := c.NewFormRequest(t.Context(), inURL, inBody)
1767 if err != nil {
1768 t.Fatalf("NewFormRequest returned unexpected error: %v", err)
1769 }
1770
1771 // test that relative URL was expanded
1772 if got, want := req.URL.String(), outURL; got != want {
1773 t.Errorf("NewFormRequest(%q) URL is %v, want %v", inURL, got, want)
1774 }
1775
1776 // test that body was form encoded
1777 body, err := io.ReadAll(req.Body)
1778 if err != nil {
1779 t.Fatalf("Error reading request body: %v", err)
1780 }
1781 if got, want := string(body), outBody; got != want {
1782 t.Errorf("NewFormRequest() Body is %v, want %v", got, want)
1783 }
1784
1785 // test that default user-agent is attached to the request
1786 if got, want := req.Header.Get("User-Agent"), c.userAgent; got != want {
1787 t.Errorf("NewFormRequest() User-Agent is %v, want %v", got, want)
1788 }
1789
1790 apiVersion := req.Header.Get(headerAPIVersion)
1791 if got, want := apiVersion, defaultAPIVersion; got != want {
1792 t.Errorf("NewFormRequest() %v header is %v, want %v", headerAPIVersion, got, want)
1793 }
1794
1795 req, err = c.NewFormRequest(t.Context(), inURL, inBody, WithVersion("2022-11-29"))
1796 if err != nil {
1797 t.Fatalf("NewFormRequest with WithVersion returned unexpected error: %v", err)
1798 }
1799 apiVersion = req.Header.Get(headerAPIVersion)
1800 if got, want := apiVersion, "2022-11-29"; got != want {
1801 t.Errorf("NewFormRequest() %v header is %v, want %v", headerAPIVersion, got, want)
1802 }
1803}
1804
1805func TestNewFormRequest_badURL(t *testing.T) {
1806 t.Parallel()

Callers

nothing calls this directly

Calls 6

mustNewClientFunction · 0.85
WithVersionFunction · 0.85
AddMethod · 0.80
NewFormRequestMethod · 0.80
StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…