-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
actions.go
89 lines (73 loc) · 1.77 KB
/
actions.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
package repos
import (
"log"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
)
// this implements the "when" part of given/when/then
//
// none of the func implement error checks, and that is complete intended, you should check for errors
// using the Then()
type Actions struct {
context *Context
lastOutput string
lastError error
ignoreErrors bool
}
func (a *Actions) IgnoreErrors() *Actions {
a.ignoreErrors = true
return a
}
func (a *Actions) DoNotIgnoreErrors() *Actions {
a.ignoreErrors = false
return a
}
func (a *Actions) Create(args ...string) *Actions {
args = a.prepareCreateArgs(args)
// are you adding new context values? if you only use them for this func, then use args instead
a.runCli(args...)
return a
}
func (a *Actions) prepareCreateArgs(args []string) []string {
a.context.t.Helper()
args = append([]string{
"repo", "add", a.context.path,
}, args...)
if a.context.project != "" {
args = append(args, "--project", a.context.project)
}
return args
}
func (a *Actions) Delete() *Actions {
a.context.t.Helper()
a.runCli("repo", "rm", a.context.path)
return a
}
func (a *Actions) List() *Actions {
a.context.t.Helper()
a.runCli("repo", "list")
return a
}
func (a *Actions) Get() *Actions {
a.context.t.Helper()
a.runCli("repo", "get", a.context.path)
return a
}
func (a *Actions) Path(path string) *Actions {
a.context.path = path
return a
}
func (a *Actions) Project(project string) *Actions {
a.context.project = project
return a
}
func (a *Actions) Then() *Consequences {
a.context.t.Helper()
return &Consequences{a.context, a}
}
func (a *Actions) runCli(args ...string) {
a.context.t.Helper()
a.lastOutput, a.lastError = fixture.RunCli(args...)
if !a.ignoreErrors && a.lastError != nil {
log.Fatal(a.lastOutput)
}
}