MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / TestPluginPublish_Unauthorized

Function TestPluginPublish_Unauthorized

cli/cmd/plugin_publish_test.go:328–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

326}
327
328func 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
353func checkAuthHeader(t *testing.T, r *http.Request) {
354 t.Helper()

Callers

nothing calls this directly

Calls 7

testCommandArgsFunction · 0.85
NewCmdRootFunction · 0.70
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
HeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected