-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathtables_test.go
More file actions
66 lines (59 loc) · 1.57 KB
/
tables_test.go
File metadata and controls
66 lines (59 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cmd
import (
"path"
"runtime"
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
func getTablesCommand(t *testing.T, config string, format string) (*cobra.Command, string) {
t.Helper()
_, filename, _, _ := runtime.Caller(0)
currentDir := path.Dir(filename)
testConfig := path.Join(currentDir, "testdata", config)
tmpDir := t.TempDir()
logFileName := path.Join(tmpDir, "cloudquery.log")
outputDirectory := path.Join(tmpDir, "cq-docs")
cmd := NewCmdRoot()
args := []string{"tables", testConfig, "--cq-dir", tmpDir, "--log-file-name", logFileName, "--output-dir", outputDirectory}
if format != "" {
args = append(args, "--format", format)
}
cmd.SetArgs(args)
return cmd, tmpDir
}
func TestTables(t *testing.T) {
configs := []struct {
name string
config string
format string
}{
{
name: "should generate tables in default format",
config: "multiple-sources.yml",
},
{
name: "should generate tables in json format",
config: "multiple-sources.yml",
format: "json",
},
{
name: "should generate tables in markdown format",
config: "multiple-sources.yml",
format: "markdown",
},
}
for _, tc := range configs {
t.Run(tc.name, func(t *testing.T) {
defer CloseLogFile()
cmd, cqDir := getTablesCommand(t, tc.config, tc.format)
commandError := cmd.Execute()
require.NoError(t, commandError)
if tc.format == "markdown" {
require.FileExists(t, path.Join(cqDir, "cq-docs/test/README.md"))
} else {
require.FileExists(t, path.Join(cqDir, "cq-docs/test/__tables.json"))
}
})
}
}