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

Function TestPluginPublish

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

Source from the content-addressed store, hash-verified

19)
20
21func TestPluginPublish(t *testing.T) {
22 type testCase struct {
23 name string
24 distDir string
25 args []string
26 }
27
28 var testCases = []testCase{
29 {
30 name: "old package json with old command line args format",
31 distDir: "testdata/dist-v1-no-team-package-json",
32 args: []string{"plugin", "publish", "cloudquery/test", "--dist-dir", "testdata/dist-v1-no-team-package-json"},
33 },
34 {
35 name: "new package json with old command line args format",
36 distDir: "testdata/dist-v1-with-team-package-json",
37 args: []string{"plugin", "publish", "cloudquery/test", "--dist-dir", "testdata/dist-v1-with-team-package-json"},
38 },
39 {
40 name: "new package json with new command line args format (no args)",
41 distDir: "testdata/dist-v1-with-team-package-json",
42 args: []string{"plugin", "publish", "--dist-dir", "testdata/dist-v1-with-team-package-json"},
43 },
44 }
45
46 for _, tc := range testCases {
47 t.Run(tc.name, func(t *testing.T) {
48 t.Setenv("CLOUDQUERY_API_KEY", "testkey")
49 wantCalls := map[string]int{
50 "PUT /plugins/cloudquery/source/test/versions/v1.2.3": 1,
51 "PUT /plugins/cloudquery/source/test/versions/v1.2.3/tables": 1,
52 "POST /plugins/cloudquery/source/test/versions/v1.2.3/docs": 1,
53 "POST /plugins/cloudquery/source/test/versions/v1.2.3/assets/linux_amd64": 1,
54 "POST /plugins/cloudquery/source/test/versions/v1.2.3/assets/darwin_amd64": 1,
55 "PUT /upload-linux": 1,
56 "PUT /upload-darwin": 1,
57 }
58 gotCalls := map[string]int{}
59 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60 w.Header().Set("Content-Type", "application/json")
61 gotCalls[r.Method+" "+r.URL.Path]++
62 switch r.URL.Path {
63 case "/plugins/cloudquery/source/test/versions/v1.2.3":
64 checkAuthHeader(t, r)
65 w.WriteHeader(http.StatusCreated)
66 _, err := w.Write([]byte(`{"name": "v1.2.3"}`))
67 require.NoError(t, err)
68 checkCreatePluginVersionRequest(t, r)
69 case "/plugins/cloudquery/source/test/versions/v1.2.3/tables":
70 checkAuthHeader(t, r)
71 w.WriteHeader(http.StatusCreated)
72 _, err := w.Write([]byte(`{}`))
73 require.NoError(t, err)
74 checkCreateTablesRequest(t, r)
75 case "/plugins/cloudquery/source/test/versions/v1.2.3/docs":
76 checkAuthHeader(t, r)
77 w.WriteHeader(http.StatusCreated)
78 _, err := w.Write([]byte(`{}`))

Callers

nothing calls this directly

Calls 11

checkAuthHeaderFunction · 0.85
checkCreateTablesRequestFunction · 0.85
checkCreateDocsRequestFunction · 0.85
testCommandArgsFunction · 0.85
RunMethod · 0.80
NewCmdRootFunction · 0.70
WriteMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected