forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.go
More file actions
158 lines (131 loc) · 3.75 KB
/
cli_test.go
File metadata and controls
158 lines (131 loc) · 3.75 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package integrationtest_test
import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"strconv"
"testing"
"time"
"github.com/briandowns/spinner"
"github.com/hasura/graphql-engine/cli/v2"
integrationtest "github.com/hasura/graphql-engine/cli/v2/integration_test"
"github.com/hasura/graphql-engine/cli/v2/internal/testutil"
"github.com/spf13/viper"
v2 "github.com/hasura/graphql-engine/cli/v2/integration_test/v2"
v3 "github.com/hasura/graphql-engine/cli/v2/integration_test/v3"
"github.com/sirupsen/logrus/hooks/test"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func TestCommands(t *testing.T) {
// Run tests only for config version v2
t.Run("config=v2", func(t *testing.T) {
ec := cli.NewExecutionContext()
ec.Config = &cli.Config{}
logger, _ := test.NewNullLogger()
ec.Logger = logger
ec.Spinner = spinner.New(spinner.CharSets[7], 100*time.Millisecond)
ec.Spinner.Writer = ioutil.Discard
ec.Viper = viper.New()
ec.Stdout = os.Stdout
ec.Stderr = os.Stderr
initDir := filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000)))
defer os.RemoveAll(initDir)
hasuraPort, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
defer teardown()
// This will prepare the execution context, so no need to run ec.Prepare() on all the other tests
t.Run("prepare", func(t *testing.T) {
integrationtest.TestPrepare(t, ec)
})
skip(t)
// This will init the project dir
t.Run("init command", func(t *testing.T) {
v2.TestInitCmd(t, ec, initDir, hasuraPort)
})
skip(t)
// This will validate the project dir
t.Run("validate", func(t *testing.T) {
integrationtest.TestValidate(t, ec)
})
skip(t)
t.Run("console command", func(t *testing.T) {
v2.TestConsoleCmd(t, ec)
})
skip(t)
t.Run("migrate commands", func(t *testing.T) {
v2.TestMigrateCmd(t, ec)
})
skip(t)
t.Run("metadata commands", func(t *testing.T) {
v2.TestMetadataCmd(t, ec)
})
skip(t)
t.Run("seed create command", func(t *testing.T) {
v2.TestSeedsCreateCmd(t, ec)
})
skip(t)
t.Run("seed apply commands", func(t *testing.T) {
v2.TestSeedsApplyCmd(t, ec)
})
})
t.Run("config=v3", func(t *testing.T) {
ec := cli.NewExecutionContext()
ec.Config = &cli.Config{}
logger, _ := test.NewNullLogger()
ec.Logger = logger
ec.Spinner = spinner.New(spinner.CharSets[7], 100*time.Millisecond)
ec.Spinner.Writer = ioutil.Discard
ec.Viper = viper.New()
ec.Stdout = os.Stdout
ec.Stderr = os.Stderr
initDir := filepath.Join(os.TempDir(), "hasura-cli-test-"+strconv.Itoa(rand.Intn(1000)))
defer os.RemoveAll(initDir)
hasuraPort, teardown := testutil.StartHasura(t, testutil.HasuraDockerImage)
defer teardown()
// This will prepare the execution context, so no need to run ec.Prepare() on all the other tests
t.Run("prepare", func(t *testing.T) {
integrationtest.TestPrepare(t, ec)
})
skip(t)
// This will init the project dir
t.Run("init command", func(t *testing.T) {
v3.TestInitCmd(t, ec, initDir, hasuraPort)
})
skip(t)
// This will validate the project dir
t.Run("validate", func(t *testing.T) {
integrationtest.TestValidate(t, ec)
})
skip(t)
t.Run("console command", func(t *testing.T) {
v3.TestConsoleCmd(t, ec)
})
skip(t)
t.Run("migrate commands", func(t *testing.T) {
v3.TestMigrateCmd(t, ec)
})
skip(t)
t.Run("metadata commands", func(t *testing.T) {
v3.TestMetadataCmd(t, ec)
})
skip(t)
t.Run("seed create command", func(t *testing.T) {
v3.TestSeedsCreateCmd(t, ec)
})
skip(t)
t.Run("seed apply commands", func(t *testing.T) {
v3.TestSeedsApplyCmd(t, ec)
})
skip(t)
t.Run("deploy commands", func(t *testing.T) {
v3.TestDeployCmd(t, ec)
})
})
}
func skip(t *testing.T) {
if t.Failed() {
t.SkipNow()
}
}