MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / TestPluginPublishFinalize

Function TestPluginPublishFinalize

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

Source from the content-addressed store, hash-verified

117}
118
119func TestPluginPublishFinalize(t *testing.T) {
120 t.Setenv("CLOUDQUERY_API_KEY", "testkey")
121
122 wantCalls := map[string]int{
123 "PUT /plugins/cloudquery/source/test/versions/v1.2.3": 1,
124 "PUT /plugins/cloudquery/source/test/versions/v1.2.3/tables": 1,
125 "POST /plugins/cloudquery/source/test/versions/v1.2.3/docs": 1,
126 "POST /plugins/cloudquery/source/test/versions/v1.2.3/assets/linux_amd64": 1,
127 "POST /plugins/cloudquery/source/test/versions/v1.2.3/assets/darwin_amd64": 1,
128 "PUT /upload-linux": 1,
129 "PUT /upload-darwin": 1,
130 "PATCH /plugins/cloudquery/source/test/versions/v1.2.3": 1,
131 }
132 gotCalls := map[string]int{}
133 gotUploads := 0
134 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
135 w.Header().Set("Content-Type", "application/json")
136 gotCalls[r.Method+" "+r.URL.Path]++
137 switch r.URL.Path {
138 case "/plugins/cloudquery/source/test/versions/v1.2.3":
139 checkAuthHeader(t, r)
140 if r.Method == "PATCH" {
141 checkUpdatePluginVersionRequest(t, r)
142 if gotUploads != 2 {
143 t.Fatalf("expected 2 uploads before draft=false, got %d", gotUploads)
144 }
145 w.WriteHeader(http.StatusOK)
146 } else {
147 checkCreatePluginVersionRequest(t, r)
148 w.WriteHeader(http.StatusCreated)
149 }
150 _, err := w.Write([]byte(`{"name": "v1.2.3"}`))
151 require.NoError(t, err)
152 case "/plugins/cloudquery/source/test/versions/v1.2.3/tables":
153 checkAuthHeader(t, r)
154 w.WriteHeader(http.StatusCreated)
155 _, err := w.Write([]byte(`{}`))
156 require.NoError(t, err)
157 checkCreateTablesRequest(t, r)
158 case "/plugins/cloudquery/source/test/versions/v1.2.3/docs":
159 checkAuthHeader(t, r)
160 w.WriteHeader(http.StatusCreated)
161 _, err := w.Write([]byte(`{}`))
162 require.NoError(t, err)
163 checkCreateDocsRequest(t, r, "testdata/dist-v1-with-team-package-json")
164 case "/plugins/cloudquery/source/test/versions/v1.2.3/assets/linux_amd64":
165 checkAuthHeader(t, r)
166 w.WriteHeader(http.StatusCreated)
167 _, err := w.Write([]byte(fmt.Sprintf(`{"url": "%s"}`, "http://"+r.Host+"/upload-linux")))
168 require.NoError(t, err)
169 case "/plugins/cloudquery/source/test/versions/v1.2.3/assets/darwin_amd64":
170 checkAuthHeader(t, r)
171 w.WriteHeader(http.StatusCreated)
172 _, err := w.Write([]byte(fmt.Sprintf(`{"url": "%s"}`, "http://"+r.Host+"/upload-darwin")))
173 require.NoError(t, err)
174 case "/upload-linux":
175 w.WriteHeader(http.StatusOK)
176 _, err := w.Write([]byte(`{}`))

Callers

nothing calls this directly

Calls 11

checkAuthHeaderFunction · 0.85
checkCreateTablesRequestFunction · 0.85
checkCreateDocsRequestFunction · 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