-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_test.go
More file actions
220 lines (212 loc) · 7.37 KB
/
Copy pathdeploy_test.go
File metadata and controls
220 lines (212 loc) · 7.37 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package main
import (
"os"
"path/filepath"
"reflect"
"testing"
"time"
"github.com/stackrox/roxie/internal/deployer"
"github.com/stackrox/roxie/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewDeployCmd_Flags(t *testing.T) {
configFilePath := filepath.Join(t.TempDir(), "config.yaml")
tests := []struct {
name string
config string
args []string
assert func(t *testing.T, cfg deployer.Config)
}{
{
name: "exposure loadbalancer",
args: []string{"--exposure", "loadbalancer"},
assert: func(t *testing.T, cfg deployer.Config) {
require.NotNil(t, cfg.Central.Exposure, "Central.Exposure should be set")
assert.Equal(t, types.ExposureLoadBalancer, *cfg.Central.Exposure, "Central.Exposure mismatch")
},
},
{
name: "resources small",
args: []string{"--resources", "small"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, types.ResourceProfileSmall, cfg.Central.ResourceProfile, "Central.ResourceProfile mismatch")
assert.Equal(t, types.ResourceProfileSmall, cfg.SecuredCluster.ResourceProfile, "SecuredCluster.ResourceProfile mismatch")
},
},
{
name: "tag short flag",
args: []string{"-t", "4.7.0"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "4.7.0", cfg.Roxie.Version, "Roxie.Version mismatch")
},
},
{
name: "tag long flag",
args: []string{"--tag", "4.7.0"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "4.7.0", cfg.Roxie.Version, "Roxie.Version mismatch")
},
},
{
name: "port-forwarding enabled",
args: []string{"--port-forwarding"},
assert: func(t *testing.T, cfg deployer.Config) {
require.NotNil(t, cfg.Central.PortForwarding, "Central.PortForwarding should be set")
assert.True(t, *cfg.Central.PortForwarding, "Central.PortForwarding mismatch")
},
},
{
name: "port-forwarding disabled",
args: []string{"--port-forwarding=false"},
assert: func(t *testing.T, cfg deployer.Config) {
require.NotNil(t, cfg.Central.PortForwarding, "Central.PortForwarding should be set")
assert.False(t, *cfg.Central.PortForwarding, "Central.PortForwarding mismatch")
},
},
{
name: "single-namespace",
args: []string{"--single-namespace"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "stackrox", cfg.Central.Namespace, "Central.Namespace mismatch")
assert.Equal(t, "stackrox", cfg.SecuredCluster.Namespace, "SecuredCluster.Namespace mismatch")
},
},
{
name: "central-wait",
args: []string{"--central-wait", "10m"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, 10*time.Minute, cfg.Central.DeployTimeout, "Central.DeployTimeout mismatch")
},
},
{
name: "secured-cluster-wait",
args: []string{"--secured-cluster-wait", "7m"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, 7*time.Minute, cfg.SecuredCluster.DeployTimeout, "SecuredCluster.DeployTimeout mismatch")
},
},
{
name: "early-readiness",
args: []string{"--early-readiness"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.True(t, cfg.Central.EarlyReadinessEnabled(), "Central.EarlyReadiness mismatch")
assert.True(t, cfg.SecuredCluster.EarlyReadinessEnabled(), "SecuredCluster.EarlyReadiness mismatch")
},
},
{
name: "disable early-readiness",
args: []string{"--early-readiness=false"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.False(t, cfg.Central.EarlyReadinessEnabled(), "Central.EarlyReadiness mismatch")
assert.False(t, cfg.SecuredCluster.EarlyReadinessEnabled(), "SecuredCluster.EarlyReadiness mismatch")
},
},
{
name: "pause-reconciliation",
args: []string{"--pause-reconciliation"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.True(t, cfg.Central.PauseReconciliation, "Central.PauseReconciliation mismatch")
assert.True(t, cfg.SecuredCluster.PauseReconciliation, "SecuredCluster.PauseReconciliation mismatch")
},
},
{
name: "olm",
args: []string{"--olm"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.True(t, cfg.Operator.DeployViaOlm, "Operator.DeployViaOlm mismatch")
},
},
{
name: "disable deploy-operator",
args: []string{"--deploy-operator=false"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.True(t, cfg.Operator.SkipDeployment, "Operator.SkipDeployment mismatch")
},
},
{
name: "multiple flags combined",
args: []string{"--tag", "4.7.0", "--exposure", "loadbalancer", "--early-readiness", "--resources", "small"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "4.7.0", cfg.Roxie.Version, "Roxie.Version mismatch")
require.NotNil(t, cfg.Central.Exposure, "Central.Exposure should be set")
assert.Equal(t, types.ExposureLoadBalancer, *cfg.Central.Exposure, "Central.Exposure mismatch")
assert.True(t, cfg.Central.EarlyReadinessEnabled(), "Central.EarlyReadiness mismatch")
assert.True(t, cfg.SecuredCluster.EarlyReadinessEnabled(), "SecuredCluster.EarlyReadiness mismatch")
assert.Equal(t, types.ResourceProfileSmall, cfg.Central.ResourceProfile, "Central.ResourceProfile mismatch")
},
},
{
name: "config file can be used",
config: `
roxie:
version: 1.2.3
securedCluster:
spec:
foo: bar
`,
args: []string{"--config", configFilePath},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "1.2.3", cfg.Roxie.Version, "Roxie.Version mismatch")
assert.True(t,
reflect.DeepEqual(cfg.SecuredCluster.Spec,
map[string]interface{}{
"foo": "bar",
}),
"SecuredCluster.Spec mismatch",
)
},
},
{
name: "config file can disable early-readiness",
config: `
central:
earlyReadiness: false
`,
args: []string{"--config", configFilePath},
assert: func(t *testing.T, cfg deployer.Config) {
assert.False(t, cfg.Central.EarlyReadinessEnabled(), "Central.EarlyReadiness should be false")
},
},
{
name: "flags can override earlier specified config file",
config: `
central:
resourceProfile: small
portForwarding: true
`,
args: []string{"--config", configFilePath, "--port-forwarding=false", "--resources=medium"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, types.ResourceProfileMedium, cfg.Central.ResourceProfile, "Central.ResourceProfile mismatch")
require.NotNil(t, cfg.Central.PortForwarding, "Central.PortForwarding should be set")
assert.False(t, *cfg.Central.PortForwarding, "Central.PortForwarding mismatch")
},
},
{
name: "set expressions can be used",
args: []string{"--set", "roxie.version=0.99.1", "--set", "central.deployTimeout=4m", "--set", "securedCluster.spec.clusterName=foo"},
assert: func(t *testing.T, cfg deployer.Config) {
assert.Equal(t, "0.99.1", cfg.Roxie.Version, "version mismatch")
assert.Equal(t, 4*time.Minute, cfg.Central.DeployTimeout, "Central.DeployTimeout mismatch")
assert.Equal(t,
map[string]interface{}{
"clusterName": "foo",
},
cfg.SecuredCluster.Spec,
"SecuredCluster.Spec mismatch",
)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.config != "" {
require.NoError(t, os.WriteFile(configFilePath, []byte(tt.config), 0o644))
}
cfg := deployer.NewConfig()
cmd := newDeployCmd(&cfg)
require.NoError(t, cmd.ParseFlags(tt.args))
tt.assert(t, cfg)
})
}
}