MCPcopy
hub / github.com/cli/cli / Test_httpRequest

Function Test_httpRequest

pkg/cmd/api/http_test.go:88–341  ·  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 method string
98 p string
99 params interface{}
100 headers []string
101 }
102 type expects struct {
103 method string
104 u string
105 body string
106 headers string
107 }
108 tests := []struct {
109 name string
110 args args
111 want expects
112 wantErr bool
113 }{
114 {
115 name: "simple GET",
116 args: args{
117 client: &httpClient,
118 host: "github.com",
119 method: "GET",
120 p: "repos/octocat/spoon-knife",
121 params: nil,
122 headers: []string{},
123 },
124 wantErr: false,
125 want: expects{
126 method: "GET",
127 u: "https://api.github.com/repos/octocat/spoon-knife",
128 body: "",
129 headers: "Accept: */*\r\n",
130 },
131 },
132 {
133 name: "GET with accept header",
134 args: args{
135 client: &httpClient,
136 host: "github.com",
137 method: "GET",
138 p: "repos/octocat/spoon-knife",
139 params: nil,
140 headers: []string{"Accept: testing"},
141 },
142 wantErr: false,
143 want: expects{
144 method: "GET",
145 u: "https://api.github.com/repos/octocat/spoon-knife",

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected