MCPcopy Create free account
hub / github.com/cli/cli / Test_httpRequest

Function Test_httpRequest

pkg/cmd/api/http_test.go:88–462  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func Test_httpRequest(t *testing.T) {
89 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
90 return &http.Response{Request: req}, nil
91 }
92 httpClient := http.Client{Transport: tr}
93
94 type args struct {
95 client *http.Client
96 host string
97 apiHost string
98 method string
99 p string
100 params any
101 headers []string
102 }
103 type expects struct {
104 method string
105 u string
106 path string // decoded path, checked when non-empty
107 rawURLString string // encoded URL from req.URL.String(), checked when non-empty
108 body string
109 headers string
110 contentLength int64
111 }
112 tests := []struct {
113 name string
114 args args
115 want expects
116 wantErr bool
117 }{
118 {
119 name: "simple GET",
120 args: args{
121 client: &httpClient,
122 host: "github.com",
123 method: "GET",
124 p: "repos/octocat/spoon-knife",
125 params: nil,
126 headers: []string{},
127 },
128 wantErr: false,
129 want: expects{
130 method: "GET",
131 u: "https://api.github.com/repos/octocat/spoon-knife",
132 body: "",
133 headers: "Accept: */*\r\n",
134 },
135 },
136 {
137 name: "GET with accept header",
138 args: args{
139 client: &httpClient,
140 host: "github.com",
141 method: "GET",
142 p: "repos/octocat/spoon-knife",
143 params: nil,
144 headers: []string{"Accept: testing"},
145 },

Callers

nothing calls this directly

Calls 4

httpRequestFunction · 0.85
RunMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected