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

Function TestTestConnection

cli/cmd/test_connection_test.go:14–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestTestConnection(t *testing.T) {
15 configs := []struct {
16 name string
17 config string
18 errors []string
19 }{
20 {
21 name: "multiple test sources should pass validation",
22 config: "multiple-sources.yml",
23 },
24 {
25 name: "bad AWS and Postgres auth should fail validation",
26 config: "test-connection-bad-connection.yml",
27 errors: []string{"cloudflare (cloudquery/cloudflare@v", "postgresql (cloudquery/postgresql@v"},
28 },
29 {
30 name: "source with no destination should pass validation",
31 config: "source-no-destination.yml",
32 },
33 }
34 _, filename, _, _ := runtime.Caller(0)
35 currentDir := path.Dir(filename)
36
37 for _, tc := range configs {
38 t.Run(tc.name, func(t *testing.T) {
39 testConfig := path.Join(currentDir, "testdata", tc.config)
40 cmd := NewCmdRoot()
41 baseArgs := testCommandArgs(t)
42 cmd.SetArgs(append([]string{"test-connection", testConfig}, baseArgs...))
43 err := cmd.Execute()
44 if len(tc.errors) > 0 {
45 var errs *testConnectionFailures
46 require.ErrorAs(t, err, &errs)
47 require.Len(t, errs.failed, len(tc.errors))
48 for i, want := range tc.errors {
49 assert.Contains(t, errs.failed[i].PluginRef, want)
50 }
51 } else {
52 assert.NoError(t, err)
53 }
54
55 // check that log was written and contains some lines from the plugin
56 b, logFileError := os.ReadFile(baseArgs[3])
57 logContent := string(b)
58 require.NoError(t, logFileError, "failed to read cloudquery.log")
59 require.NotEmpty(t, logContent, "cloudquery.log empty; expected some logs")
60 })
61 }
62}
63
64func TestTestConnection_IsolatedPluginEnvironmentsInCloud(t *testing.T) {
65 configs := []struct {

Callers

nothing calls this directly

Calls 3

testCommandArgsFunction · 0.85
RunMethod · 0.80
NewCmdRootFunction · 0.70

Tested by

no test coverage detected