github.com/argoproj/argo-cd/v2@v2.10.9/test/e2e/fixture/repos/actions.go (about)

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