-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
context.go
310 lines (255 loc) · 7.05 KB
/
context.go
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package app
import (
"testing"
"time"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/certs"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/gpgkeys"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/repos"
"github.com/argoproj/argo-cd/v2/util/env"
"github.com/argoproj/argo-cd/v2/util/settings"
)
// this implements the "given" part of given/when/then
type Context struct {
t *testing.T
path string
chart string
repoURLType fixture.RepoURLType
// seconds
timeout int
name string
destServer string
destName string
env string
parameters []string
namePrefix string
nameSuffix string
resource string
prune bool
configManagementPlugin string
async bool
localPath string
project string
revision string
force bool
directoryRecurse bool
replace bool
helmPassCredentials bool
helmSkipCrds bool
}
func Given(t *testing.T) *Context {
fixture.EnsureCleanState(t)
return GivenWithSameState(t)
}
func GivenWithSameState(t *testing.T) *Context {
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
// for any context.
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
return &Context{t: t, destServer: v1alpha1.KubernetesInternalAPIServerAddr, repoURLType: fixture.RepoURLTypeFile, name: fixture.Name(), timeout: timeout, project: "default", prune: true}
}
func (c *Context) GPGPublicKeyAdded() *Context {
gpgkeys.AddGPGPublicKey()
return c
}
func (c *Context) GPGPublicKeyRemoved() *Context {
gpgkeys.DeleteGPGPublicKey()
return c
}
func (c *Context) CustomCACertAdded() *Context {
certs.AddCustomCACert()
return c
}
func (c *Context) CustomSSHKnownHostsAdded() *Context {
certs.AddCustomSSHKnownHostsKeys()
return c
}
func (c *Context) HTTPSRepoURLAdded(withCreds bool) *Context {
repos.AddHTTPSRepo(false, withCreds, fixture.RepoURLTypeHTTPS)
return c
}
func (c *Context) HTTPSInsecureRepoURLAdded(withCreds bool) *Context {
repos.AddHTTPSRepo(true, withCreds, fixture.RepoURLTypeHTTPS)
return c
}
func (c *Context) HTTPSInsecureRepoURLWithClientCertAdded() *Context {
repos.AddHTTPSRepoClientCert(true)
return c
}
func (c *Context) HTTPSRepoURLWithClientCertAdded() *Context {
repos.AddHTTPSRepoClientCert(false)
return c
}
func (c *Context) SubmoduleHTTPSRepoURLAdded(withCreds bool) *Context {
fixture.CreateSubmoduleRepos("https")
repos.AddHTTPSRepo(false, withCreds, fixture.RepoURLTypeHTTPSSubmoduleParent)
return c
}
func (c *Context) SSHRepoURLAdded(withCreds bool) *Context {
repos.AddSSHRepo(false, withCreds, fixture.RepoURLTypeSSH)
return c
}
func (c *Context) SSHInsecureRepoURLAdded(withCreds bool) *Context {
repos.AddSSHRepo(true, withCreds, fixture.RepoURLTypeSSH)
return c
}
func (c *Context) SubmoduleSSHRepoURLAdded(withCreds bool) *Context {
fixture.CreateSubmoduleRepos("ssh")
repos.AddSSHRepo(false, withCreds, fixture.RepoURLTypeSSHSubmoduleParent)
return c
}
func (c *Context) HelmRepoAdded(name string) *Context {
repos.AddHelmRepo(name)
return c
}
func (c *Context) HelmOCIRepoAdded(name string) *Context {
repos.AddHelmOCIRepo(name)
return c
}
func (c *Context) PushChartToOCIRegistry(chartPathName, chartName, chartVersion string) *Context {
repos.PushChartToOCIRegistry(chartPathName, chartName, chartVersion)
return c
}
func (c *Context) HTTPSCredentialsUserPassAdded() *Context {
repos.AddHTTPSCredentialsUserPass()
return c
}
func (c *Context) HelmHTTPSCredentialsUserPassAdded() *Context {
repos.AddHelmHTTPSCredentialsTLSClientCert()
return c
}
func (c *Context) HelmoOCICredentialsWithoutUserPassAdded() *Context {
repos.AddHelmoOCICredentialsWithoutUserPass()
return c
}
func (c *Context) HTTPSCredentialsTLSClientCertAdded() *Context {
repos.AddHTTPSCredentialsTLSClientCert()
return c
}
func (c *Context) SSHCredentialsAdded() *Context {
repos.AddSSHCredentials()
return c
}
func (c *Context) ProjectSpec(spec v1alpha1.AppProjectSpec) *Context {
fixture.SetProjectSpec(c.project, spec)
return c
}
func (c *Context) Replace() *Context {
c.replace = true
return c
}
func (c *Context) RepoURLType(urlType fixture.RepoURLType) *Context {
c.repoURLType = urlType
return c
}
func (c *Context) GetName() string {
return c.name
}
func (c *Context) Name(name string) *Context {
c.name = name
return c
}
func (c *Context) Path(path string) *Context {
c.path = path
return c
}
func (c *Context) Recurse() *Context {
c.directoryRecurse = true
return c
}
func (c *Context) Chart(chart string) *Context {
c.chart = chart
return c
}
func (c *Context) Revision(revision string) *Context {
c.revision = revision
return c
}
func (c *Context) Timeout(timeout int) *Context {
c.timeout = timeout
return c
}
func (c *Context) DestServer(destServer string) *Context {
c.destServer = destServer
return c
}
func (c *Context) DestName(destName string) *Context {
c.destName = destName
return c
}
func (c *Context) Env(env string) *Context {
c.env = env
return c
}
func (c *Context) Parameter(parameter string) *Context {
c.parameters = append(c.parameters, parameter)
return c
}
// group:kind:name
func (c *Context) SelectedResource(resource string) *Context {
c.resource = resource
return c
}
func (c *Context) NamePrefix(namePrefix string) *Context {
c.namePrefix = namePrefix
return c
}
func (c *Context) NameSuffix(nameSuffix string) *Context {
c.nameSuffix = nameSuffix
return c
}
func (c *Context) ResourceOverrides(overrides map[string]v1alpha1.ResourceOverride) *Context {
fixture.SetResourceOverrides(overrides)
return c
}
func (c *Context) ResourceFilter(filter settings.ResourcesFilter) *Context {
fixture.SetResourceFilter(filter)
return c
}
// this both configures the plugin, but forces use of it
func (c *Context) ConfigManagementPlugin(plugin v1alpha1.ConfigManagementPlugin) *Context {
fixture.SetConfigManagementPlugins(plugin)
c.configManagementPlugin = plugin.Name
return c
}
func (c *Context) And(block func()) *Context {
block()
return c
}
func (c *Context) When() *Actions {
// in case any settings have changed, pause for 1s, not great, but fine
time.Sleep(1 * time.Second)
return &Actions{context: c}
}
func (c *Context) Sleep(seconds time.Duration) *Context {
time.Sleep(seconds * time.Second)
return c
}
func (c *Context) Prune(prune bool) *Context {
c.prune = prune
return c
}
func (c *Context) Async(async bool) *Context {
c.async = async
return c
}
func (c *Context) LocalPath(localPath string) *Context {
c.localPath = localPath
return c
}
func (c *Context) Project(project string) *Context {
c.project = project
return c
}
func (c *Context) Force() *Context {
c.force = true
return c
}
func (c *Context) HelmPassCredentials() *Context {
c.helmPassCredentials = true
return c
}
func (c *Context) HelmSkipCrds() *Context {
c.helmSkipCrds = true
return c
}