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

Function TestAddonPublishFinalize

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

Source from the content-addressed store, hash-verified

104}
105
106func TestAddonPublishFinalize(t *testing.T) {
107 t.Setenv("CLOUDQUERY_API_KEY", "testkey")
108
109 wantCalls := map[string]int{
110 "PUT /addons/cloudquery/visualization/test/versions/v1.2.3": 1,
111 "POST /addons/cloudquery/visualization/test/versions/v1.2.3/assets": 1,
112 "PUT /upload-zip": 1,
113 "PATCH /addons/cloudquery/visualization/test/versions/v1.2.3": 1,
114 }
115 gotCalls := map[string]int{}
116 gotUploads := 0
117 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
118 w.Header().Set("Content-Type", "application/json")
119 gotCalls[r.Method+" "+r.URL.Path]++
120 switch r.URL.Path {
121 case "/addons/cloudquery/visualization/test/versions/v1.2.3":
122 checkAuthHeader(t, r)
123 if r.Method == "PATCH" {
124 checkUpdateAddonVersionRequest(t, r)
125 if gotUploads != 1 {
126 t.Fatalf("expected 1 upload before draft=false, got %d", gotUploads)
127 }
128 w.WriteHeader(http.StatusOK)
129 } else {
130 checkCreateAddonVersionRequest(t, r)
131 w.WriteHeader(http.StatusCreated)
132 }
133 _, err := w.Write([]byte(`{"name": "v1.2.3"}`))
134 require.NoError(t, err)
135 case "/addons/cloudquery/visualization/test/versions/v1.2.3/assets":
136 checkAuthHeader(t, r)
137 w.WriteHeader(http.StatusCreated)
138 _, err := w.Write([]byte(fmt.Sprintf(`{"url": "%s"}`, "http://"+r.Host+"/upload-zip")))
139 require.NoError(t, err)
140 case "/upload-zip":
141 w.WriteHeader(http.StatusOK)
142 _, err := w.Write([]byte(`{}`))
143 require.NoError(t, err)
144 gotUploads++
145 }
146 }))
147 defer ts.Close()
148
149 t.Setenv(envAPIURL, ts.URL)
150
151 cmd := NewCmdRoot()
152 args := append([]string{"addon", "publish", "testdata/addon-v1/manifest.json", "v1.2.3", "--finalize"}, testCommandArgs(t)...)
153 cmd.SetArgs(args)
154 err := cmd.Execute()
155 if err != nil {
156 t.Fatal(err)
157 }
158 if diff := cmp.Diff(wantCalls, gotCalls); diff != "" {
159 t.Fatalf("mismatch (-want +got):\n%s", diff)
160 }
161}
162
163func TestAddonPublish_Unauthorized(t *testing.T) {

Callers

nothing calls this directly

Calls 9

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