(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func TestPluginPublish_Unauthorized(t *testing.T) { |
| 329 | t.Setenv("CLOUDQUERY_API_KEY", "badkey") |
| 330 | |
| 331 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 332 | w.Header().Set("Content-Type", "application/json") |
| 333 | w.WriteHeader(http.StatusUnauthorized) |
| 334 | _, err := w.Write([]byte(`{"message": "unauthorized"}`)) |
| 335 | require.NoError(t, err) |
| 336 | })) |
| 337 | defer ts.Close() |
| 338 | |
| 339 | t.Setenv(envAPIURL, ts.URL) |
| 340 | |
| 341 | cmd := NewCmdRoot() |
| 342 | args := append([]string{"plugin", "publish", "--dist-dir", "testdata/dist-v1-with-team-package-json", "--finalize"}, testCommandArgs(t)...) |
| 343 | cmd.SetArgs(args) |
| 344 | err := cmd.Execute() |
| 345 | if err == nil { |
| 346 | t.Fatal("expected error, got nil") |
| 347 | } |
| 348 | if !strings.Contains(err.Error(), "unauthorized") { |
| 349 | t.Fatalf("expected error to contain 'unauthorized', got %v", err) |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | func checkAuthHeader(t *testing.T, r *http.Request) { |
| 354 | t.Helper() |
nothing calls this directly
no test coverage detected