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

Function TestAddonPublish

cli/cmd/addon_publish_test.go:16–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestAddonPublish(t *testing.T) {
17 t.Setenv("CLOUDQUERY_API_KEY", "testkey")
18
19 wantCalls := map[string]int{
20 "PUT /addons/cloudquery/visualization/test/versions/v1.2.3": 1,
21 "POST /addons/cloudquery/visualization/test/versions/v1.2.3/assets": 1,
22 "PUT /upload-zip": 1,
23 }
24 gotCalls := map[string]int{}
25 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26 w.Header().Set("Content-Type", "application/json")
27 gotCalls[r.Method+" "+r.URL.Path]++
28 switch r.URL.Path {
29 case "/addons/cloudquery/visualization/test/versions/v1.2.3":
30 checkAuthHeader(t, r)
31 w.WriteHeader(http.StatusCreated)
32 _, err := w.Write([]byte(`{"name": "v1.2.3"}`))
33 require.NoError(t, err)
34 checkCreateAddonVersionRequest(t, r)
35 case "/addons/cloudquery/visualization/test/versions/v1.2.3/assets":
36 checkAuthHeader(t, r)
37 w.WriteHeader(http.StatusCreated)
38 _, err := w.Write([]byte(fmt.Sprintf(`{"url": "%s"}`, "http://"+r.Host+"/upload-zip")))
39 require.NoError(t, err)
40 case "/upload-zip":
41 w.WriteHeader(http.StatusOK)
42 _, err := w.Write([]byte(`{}`))
43 require.NoError(t, err)
44 }
45 }))
46 defer ts.Close()
47
48 cmd := NewCmdRoot()
49 t.Setenv(envAPIURL, ts.URL)
50 args := append([]string{"addon", "publish", "testdata/addon-v1/manifest.json", "v1.2.3"}, testCommandArgs(t)...)
51 cmd.SetArgs(args)
52 err := cmd.Execute()
53 if err != nil {
54 t.Fatal(err)
55 }
56 if diff := cmp.Diff(wantCalls, gotCalls); diff != "" {
57 t.Fatalf("mismatch (-want +got):\n%s", diff)
58 }
59}
60
61func TestAddonPublishEmbedded(t *testing.T) {
62 t.Setenv("CLOUDQUERY_API_KEY", "testkey")

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected