MCPcopy
hub / github.com/git-lfs/git-lfs / TestVerboseEnabledWithDebugging

Function TestVerboseEnabledWithDebugging

lfshttp/verbose_test.go:134–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestVerboseEnabledWithDebugging(t *testing.T) {
135 var called uint32
136 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
137 atomic.AddUint32(&called, 1)
138 t.Logf("srv req %s %s", r.Method, r.URL.Path)
139 assert.Equal(t, "POST", r.Method)
140
141 assert.Equal(t, "Basic ABC", r.Header.Get("Authorization"))
142 body := &verboseTest{}
143 err := json.NewDecoder(r.Body).Decode(body)
144 assert.Nil(t, err)
145 assert.Equal(t, "Verbose", body.Test)
146 w.Header().Set("Content-Type", "application/json")
147 w.Write([]byte(`{"Status":"Ok"}`))
148 }))
149 defer srv.Close()
150
151 out := &bytes.Buffer{}
152 c, _ := NewClient(nil)
153 c.Verbose = true
154 c.VerboseOut = out
155 c.DebuggingVerbose = true
156
157 req, err := http.NewRequest("POST", srv.URL, nil)
158 req.Header.Set("Authorization", "Basic ABC")
159 req.Header.Set("Content-Type", "application/json")
160 require.Nil(t, err)
161 require.Nil(t, MarshalToRequest(req, verboseTest{"Verbose"}))
162
163 res, err := c.Do(req)
164 require.Nil(t, err)
165 io.Copy(io.Discard, res.Body)
166 res.Body.Close()
167
168 assert.Equal(t, 200, res.StatusCode)
169 assert.EqualValues(t, 1, called)
170
171 s := out.String()
172 t.Log(s)
173
174 expected := []string{
175 "> Host: 127.0.0.1:",
176 "\n> Authorization: Basic ABC\n",
177 "\n> Content-Type: application/json\n",
178 "\n> \n" + `{"Test":"Verbose"}` + "\n\n",
179
180 "\n< HTTP/1.1 200 OK\n",
181 "\n< Content-Type: application/json\n",
182 "\n< \n" + `{"Status":"Ok"}`,
183 }
184
185 for _, substr := range expected {
186 if !assert.True(t, strings.Contains(s, substr)) {
187 t.Logf("missing: %q", substr)
188 }
189 }
190}
191

Callers

nothing calls this directly

Calls 13

DoMethod · 0.95
LogfMethod · 0.80
LogMethod · 0.80
NewClientFunction · 0.70
MarshalToRequestFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
ContainsMethod · 0.65
EqualMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected