-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
context.go
73 lines (60 loc) · 1.45 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
package cluster
import (
"testing"
"time"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
"github.com/argoproj/argo-cd/v2/util/env"
)
// this implements the "given" part of given/when/then
type Context struct {
t *testing.T
// seconds
timeout int
name string
project string
server string
upsert bool
namespaces []string
}
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, name: fixture.Name(), timeout: timeout, project: "default"}
}
func (c *Context) GetName() string {
return c.name
}
func (c *Context) Name(name string) *Context {
c.name = name
return c
}
func (c *Context) Server(server string) *Context {
c.server = server
return c
}
func (c *Context) Namespaces(namespaces []string) *Context {
c.namespaces = namespaces
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) Project(project string) *Context {
c.project = project
return c
}
func (c *Context) Upsert(upsert bool) *Context {
c.upsert = upsert
return c
}