github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/fixture/account/actions.go (about)

     1  package project
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
     9  )
    10  
    11  // this implements the "when" part of given/when/then
    12  //
    13  // none of the func implement error checks, and that is complete intended, you should check for errors
    14  // using the Then()
    15  type Actions struct {
    16  	context    *Context
    17  	lastOutput string
    18  	lastError  error
    19  }
    20  
    21  func (a *Actions) prepareCanIGetLogsArgs() []string {
    22  	a.context.t.Helper()
    23  	return []string{
    24  		"account", "can-i", "get", "logs", a.context.project + "/*",
    25  	}
    26  }
    27  
    28  func (a *Actions) CanIGetLogs() *Actions {
    29  	a.context.t.Helper()
    30  	a.runCli(a.prepareCanIGetLogsArgs()...)
    31  	return a
    32  }
    33  
    34  func (a *Actions) prepareSetPasswordArgs(account string) []string {
    35  	a.context.t.Helper()
    36  	return []string{
    37  		"account", "update-password", "--account", account, "--current-password", fixture.AdminPassword, "--new-password", fixture.DefaultTestUserPassword,
    38  	}
    39  }
    40  
    41  func (a *Actions) Create() *Actions {
    42  	a.context.t.Helper()
    43  	require.NoError(a.context.t, fixture.SetAccounts(map[string][]string{
    44  		a.context.name: {"login"},
    45  	}))
    46  	_, _ = fixture.RunCli(a.prepareSetPasswordArgs(a.context.name)...)
    47  	return a
    48  }
    49  
    50  func (a *Actions) SetPermissions(permissions []fixture.ACL, roleName string) *Actions {
    51  	a.context.t.Helper()
    52  	require.NoError(a.context.t, fixture.SetPermissions(permissions, a.context.name, roleName))
    53  	return a
    54  }
    55  
    56  func (a *Actions) SetParamInSettingConfigMap(key, value string) *Actions {
    57  	a.context.t.Helper()
    58  	require.NoError(a.context.t, fixture.SetParamInSettingConfigMap(key, value))
    59  	return a
    60  }
    61  
    62  func (a *Actions) Login() *Actions {
    63  	a.context.t.Helper()
    64  	require.NoError(a.context.t, fixture.LoginAs(a.context.name))
    65  	return a
    66  }
    67  
    68  func (a *Actions) runCli(args ...string) {
    69  	a.context.t.Helper()
    70  	a.lastOutput, a.lastError = fixture.RunCli(args...)
    71  }
    72  
    73  func (a *Actions) Then() *Consequences {
    74  	a.context.t.Helper()
    75  	time.Sleep(fixture.WhenThenSleepInterval)
    76  	return &Consequences{a.context, a}
    77  }