(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestConfigureAPIBaseURL(t *testing.T) { |
| 171 | co := newCapturedOutput() |
| 172 | co.override() |
| 173 | defer co.reset() |
| 174 | |
| 175 | endpoint := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 176 | if r.URL.Path == "/ping" { |
| 177 | w.WriteHeader(http.StatusNotFound) |
| 178 | } |
| 179 | }) |
| 180 | ts := httptest.NewServer(endpoint) |
| 181 | defer ts.Close() |
| 182 | |
| 183 | testCases := []struct { |
| 184 | desc string |
| 185 | configured string |
| 186 | args []string |
| 187 | expected string |
| 188 | message string |
| 189 | err bool |
| 190 | }{ |
| 191 | { |
| 192 | desc: "It doesn't lose a configured value", |
| 193 | configured: "http://example.com", |
| 194 | args: []string{"--no-verify"}, |
| 195 | expected: "http://example.com", |
| 196 | }, |
| 197 | { |
| 198 | desc: "It writes a base url when passed as a flag", |
| 199 | configured: "", |
| 200 | args: []string{"--no-verify", "--api", "http://api.example.com"}, |
| 201 | expected: "http://api.example.com", |
| 202 | }, |
| 203 | { |
| 204 | desc: "It overwrites the base url", |
| 205 | configured: "http://old.example.com", |
| 206 | args: []string{"--no-verify", "--api", "http://replacement.example.com"}, |
| 207 | expected: "http://replacement.example.com", |
| 208 | }, |
| 209 | { |
| 210 | desc: "It validates the existing base url if we're not skipping validations", |
| 211 | configured: ts.URL, |
| 212 | args: []string{"--token", "some-token"}, // need to bypass the error message on "bare configure" |
| 213 | expected: ts.URL, |
| 214 | err: true, |
| 215 | message: "API.*cannot be reached", |
| 216 | }, |
| 217 | { |
| 218 | desc: "It validates the replacement base URL if we're not skipping validations", |
| 219 | configured: "", |
| 220 | args: []string{"--api", ts.URL}, |
| 221 | expected: "", |
| 222 | err: true, |
| 223 | message: "API.*cannot be reached", |
| 224 | }, |
| 225 | } |
| 226 | |
| 227 | for _, tc := range testCases { |
nothing calls this directly
no test coverage detected