(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func 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(`{}`)) |
nothing calls this directly
no test coverage detected