(t *testing.T)
| 59 | } |
| 60 | |
| 61 | func TestAddonPublishEmbedded(t *testing.T) { |
| 62 | t.Setenv("CLOUDQUERY_API_KEY", "testkey") |
| 63 | |
| 64 | wantCalls := map[string]int{ |
| 65 | "PUT /addons/cloudquery/visualization/test/versions/v1.2.3": 1, |
| 66 | "POST /addons/cloudquery/visualization/test/versions/v1.2.3/assets": 1, |
| 67 | "PUT /upload-zip": 1, |
| 68 | } |
| 69 | gotCalls := map[string]int{} |
| 70 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 71 | w.Header().Set("Content-Type", "application/json") |
| 72 | gotCalls[r.Method+" "+r.URL.Path]++ |
| 73 | switch r.URL.Path { |
| 74 | case "/addons/cloudquery/visualization/test/versions/v1.2.3": |
| 75 | checkAuthHeader(t, r) |
| 76 | w.WriteHeader(http.StatusCreated) |
| 77 | _, err := w.Write([]byte(`{"name": "v1.2.3"}`)) |
| 78 | require.NoError(t, err) |
| 79 | checkCreateAddonVersionRequest(t, r) |
| 80 | case "/addons/cloudquery/visualization/test/versions/v1.2.3/assets": |
| 81 | checkAuthHeader(t, r) |
| 82 | w.WriteHeader(http.StatusCreated) |
| 83 | _, err := w.Write([]byte(fmt.Sprintf(`{"url": "%s"}`, "http://"+r.Host+"/upload-zip"))) |
| 84 | require.NoError(t, err) |
| 85 | case "/upload-zip": |
| 86 | w.WriteHeader(http.StatusOK) |
| 87 | _, err := w.Write([]byte(`{}`)) |
| 88 | require.NoError(t, err) |
| 89 | } |
| 90 | })) |
| 91 | defer ts.Close() |
| 92 | |
| 93 | cmd := NewCmdRoot() |
| 94 | t.Setenv(envAPIURL, ts.URL) |
| 95 | args := append([]string{"addon", "publish", "testdata/addon-v1/manifest-embedded-message.json", "v1.2.3"}, testCommandArgs(t)...) |
| 96 | cmd.SetArgs(args) |
| 97 | err := cmd.Execute() |
| 98 | if err != nil { |
| 99 | t.Fatal(err) |
| 100 | } |
| 101 | if diff := cmp.Diff(wantCalls, gotCalls); diff != "" { |
| 102 | t.Fatalf("mismatch (-want +got):\n%s", diff) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | func TestAddonPublishFinalize(t *testing.T) { |
| 107 | t.Setenv("CLOUDQUERY_API_KEY", "testkey") |
nothing calls this directly
no test coverage detected