github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/fixture/repos/actions.go (about) 1 package repos 2 3 import ( 4 "log" 5 "time" 6 7 "github.com/argoproj/argo-cd/v3/test/e2e/fixture" 8 ) 9 10 // this implements the "when" part of given/when/then 11 // 12 // none of the func implement error checks, and that is complete intended, you should check for errors 13 // using the Then() 14 type Actions struct { 15 context *Context 16 lastOutput string 17 lastError error 18 ignoreErrors bool 19 } 20 21 func (a *Actions) IgnoreErrors() *Actions { 22 a.ignoreErrors = true 23 return a 24 } 25 26 func (a *Actions) DoNotIgnoreErrors() *Actions { 27 a.ignoreErrors = false 28 return a 29 } 30 31 func (a *Actions) Create(args ...string) *Actions { 32 args = a.prepareCreateArgs(args) 33 34 // are you adding new context values? if you only use them for this func, then use args instead 35 a.runCli(args...) 36 37 return a 38 } 39 40 func (a *Actions) prepareCreateArgs(args []string) []string { 41 a.context.t.Helper() 42 args = append([]string{ 43 "repo", "add", a.context.path, 44 }, args...) 45 if a.context.project != "" { 46 args = append(args, "--project", a.context.project) 47 } 48 return args 49 } 50 51 func (a *Actions) Delete() *Actions { 52 a.context.t.Helper() 53 a.runCli("repo", "rm", a.context.path) 54 return a 55 } 56 57 func (a *Actions) List() *Actions { 58 a.context.t.Helper() 59 a.runCli("repo", "list") 60 return a 61 } 62 63 func (a *Actions) Get() *Actions { 64 a.context.t.Helper() 65 a.runCli("repo", "get", a.context.path) 66 return a 67 } 68 69 func (a *Actions) Path(path string) *Actions { 70 a.context.path = path 71 return a 72 } 73 74 func (a *Actions) Project(project string) *Actions { 75 a.context.project = project 76 return a 77 } 78 79 func (a *Actions) Then() *Consequences { 80 a.context.t.Helper() 81 time.Sleep(fixture.WhenThenSleepInterval) 82 return &Consequences{a.context, a} 83 } 84 85 func (a *Actions) runCli(args ...string) { 86 a.context.t.Helper() 87 a.lastOutput, a.lastError = fixture.RunCli(args...) 88 if !a.ignoreErrors && a.lastError != nil { 89 log.Fatal(a.lastOutput) 90 } 91 }