(t *testing.T)
| 132 | } |
| 133 | |
| 134 | func 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 |
nothing calls this directly
no test coverage detected