(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func TestValidateConfig_HubAPI(t *testing.T) { |
| 87 | _, filename, _, _ := runtime.Caller(0) |
| 88 | currentDir := path.Dir(filename) |
| 89 | |
| 90 | // fakeHub serves canned responses for GetPluginVersion. |
| 91 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 92 | switch r.URL.Path { |
| 93 | case "/plugins/cloudquery/source/aws/versions/v1.0.0": |
| 94 | body, _ := json.Marshal(cloudquery_api.PluginVersionDetails{ |
| 95 | Name: "v1.0.0", |
| 96 | SpecJsonSchema: strPtr(`{ |
| 97 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 98 | "type": ["object","null"], |
| 99 | "properties": {"use_paid_apis": {"type": "boolean"}}, |
| 100 | "additionalProperties": false |
| 101 | }`), |
| 102 | }) |
| 103 | w.Header().Set("Content-Type", "application/json") |
| 104 | _, _ = w.Write(body) |
| 105 | case "/plugins/cloudquery/destination/pg/versions/v1.0.0": |
| 106 | body, _ := json.Marshal(cloudquery_api.PluginVersionDetails{ |
| 107 | Name: "v1.0.0", |
| 108 | SpecJsonSchema: strPtr(`{"$schema":"https://json-schema.org/draft/2020-12/schema","type":["object","null"]}`), |
| 109 | }) |
| 110 | w.Header().Set("Content-Type", "application/json") |
| 111 | _, _ = w.Write(body) |
| 112 | case "/plugins/cloudquery/source/missing/versions/v9.9.9": |
| 113 | w.WriteHeader(http.StatusNotFound) |
| 114 | _, _ = w.Write([]byte(`{"message":"not found"}`)) |
| 115 | default: |
| 116 | http.NotFound(w, r) |
| 117 | } |
| 118 | })) |
| 119 | t.Cleanup(srv.Close) |
| 120 | t.Setenv("CLOUDQUERY_API_URL", srv.URL) |
| 121 | |
| 122 | t.Run("good spec validates against Hub-returned schema (no plugin spawn)", func(t *testing.T) { |
| 123 | cmd := NewCmdRoot() |
| 124 | testConfig := path.Join(currentDir, "testdata", "validate-config-hub-good.yml") |
| 125 | baseArgs := testCommandArgs(t) |
| 126 | args := append([]string{"validate-config", testConfig}, baseArgs...) |
| 127 | cmd.SetArgs(args) |
| 128 | err := cmd.Execute() |
| 129 | require.NoError(t, err) |
| 130 | |
| 131 | logContent, readErr := os.ReadFile(baseArgs[3]) |
| 132 | require.NoError(t, readErr) |
| 133 | require.Contains(t, string(logContent), "Fetching spec schema from Hub API") |
| 134 | require.NotContains(t, string(logContent), "Initializing source") |
| 135 | }) |
| 136 | |
| 137 | t.Run("schema-violating spec fails validation", func(t *testing.T) { |
| 138 | cmd := NewCmdRoot() |
| 139 | testConfig := path.Join(currentDir, "testdata", "validate-config-hub-bad.yml") |
| 140 | baseArgs := testCommandArgs(t) |
| 141 | args := append([]string{"validate-config", testConfig}, baseArgs...) |
| 142 | cmd.SetArgs(args) |
| 143 | err := cmd.Execute() |
nothing calls this directly
no test coverage detected