-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Make
registry: cloudquery
the default registry instead of `r…
…egistry: github` (#15409) Uses ~cloudquery/plugin-pb-go#170 cloudquery/plugin-pb-go#172 (now tagged as 1.14.2) Part of cloudquery/cloudquery-issues#924 (Internal issue)
- Loading branch information
Showing
21 changed files
with
363 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
//go:build !windows | ||
|
||
package cmd | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInferRegistry(t *testing.T) { | ||
configs := []struct { | ||
name string | ||
config string | ||
outContains string | ||
wantErrContains string | ||
wantErrNotContains string | ||
}{ | ||
{ | ||
name: "infer registry success", | ||
config: ` | ||
kind: source | ||
spec: | ||
name: gcp | ||
path: cloudquery/gcp | ||
version: v10.0.0 | ||
table_concurrency: 10 | ||
destinations: [dummydest] | ||
tables: [test] | ||
--- | ||
kind: destination | ||
spec: | ||
name: dummydest | ||
path: localhost:7777 | ||
registry: grpc | ||
`, | ||
outContains: "Downloading https://storage.googleapis.com/cq-cloud-releases/cloudquery/source/gcp/v10.0.0/", | ||
wantErrContains: "", | ||
wantErrNotContains: "", | ||
}, | ||
{ | ||
name: "infer registry fail: recommend github", | ||
config: ` | ||
kind: source | ||
spec: | ||
name: gcp | ||
path: cloudquery/gcp | ||
version: v99.999.0 | ||
table_concurrency: 10 | ||
destinations: [dummydest] | ||
tables: [test] | ||
--- | ||
kind: destination | ||
spec: | ||
name: dummydest | ||
path: localhost:7777 | ||
registry: grpc | ||
`, | ||
wantErrContains: "Hint", | ||
wantErrNotContains: "", | ||
}, | ||
{ | ||
name: "no infer registry fail: don't recommend github", | ||
config: ` | ||
kind: source | ||
spec: | ||
name: gcp | ||
path: cloudquery/gcp | ||
registry: cloudquery | ||
version: v99.999.0 | ||
table_concurrency: 10 | ||
destinations: [dummydest] | ||
tables: [test] | ||
--- | ||
kind: destination | ||
spec: | ||
name: dummydest | ||
path: localhost:7777 | ||
registry: grpc | ||
`, | ||
wantErrContains: "", | ||
wantErrNotContains: "Hint", | ||
}, | ||
{ | ||
name: "no infer registry fail: don't recommend github for github", | ||
config: ` | ||
kind: source | ||
spec: | ||
name: gcp | ||
path: cloudquery/gcp | ||
registry: github | ||
version: v99.999.0 | ||
table_concurrency: 10 | ||
destinations: [dummydest] | ||
tables: [test] | ||
--- | ||
kind: destination | ||
spec: | ||
name: dummydest | ||
path: localhost:7777 | ||
registry: grpc | ||
`, | ||
wantErrContains: "", | ||
wantErrNotContains: "Hint", | ||
}, | ||
} | ||
|
||
for _, tc := range configs { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
cqDir := t.TempDir() | ||
t.Cleanup(func() { | ||
os.RemoveAll(cqDir) | ||
}) | ||
testConfig := filepath.Join(cqDir, "config.yml") | ||
logFileName := path.Join(cqDir, "cloudquery.log") | ||
err := os.WriteFile(testConfig, []byte(tc.config), 0644) | ||
require.NoError(t, err) | ||
|
||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
defer func() { | ||
os.Stdout = oldStdout | ||
}() | ||
|
||
cmd := NewCmdRoot() | ||
cmd.SetArgs([]string{"plugin", "install", testConfig, "--cq-dir", cqDir, "--log-file-name", logFileName}) | ||
err = cmd.Execute() | ||
|
||
_ = w.Close() | ||
out, _ := io.ReadAll(r) | ||
if tc.outContains != "" { | ||
require.Contains(t, string(out), tc.outContains) | ||
} | ||
|
||
if tc.wantErrContains == "" && tc.wantErrNotContains == "" { | ||
require.NoError(t, err) | ||
} | ||
if tc.wantErrContains != "" { | ||
require.ErrorContains(t, err, tc.wantErrContains) | ||
} | ||
if tc.wantErrNotContains != "" { | ||
require.Error(t, err) | ||
require.NotContains(t, err.Error(), tc.wantErrNotContains) | ||
} | ||
|
||
// check that log was written and contains some lines | ||
b, logFileError := os.ReadFile(path.Join(cqDir, "cloudquery.log")) | ||
logContent := string(b) | ||
require.NoError(t, logFileError, "failed to read cloudquery.log") | ||
require.NotEmpty(t, logContent, "cloudquery.log empty; expected some logs") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.