github.com/argoproj/argo-cd/v2@v2.10.9/test/e2e/fixture/repos/consequences.go (about) 1 package repos 2 3 import ( 4 "context" 5 "fmt" 6 7 repositorypkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository" 8 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" 9 "github.com/argoproj/argo-cd/v2/test/e2e/fixture" 10 ) 11 12 // this implements the "then" part of given/when/then 13 type Consequences struct { 14 context *Context 15 actions *Actions 16 } 17 18 func (c *Consequences) Expect() *Consequences { 19 return c 20 } 21 22 func (c *Consequences) And(block func(repository *v1alpha1.Repository, err error)) *Consequences { 23 c.context.t.Helper() 24 block(c.repo()) 25 return c 26 } 27 28 func (c *Consequences) AndCLIOutput(block func(output string, err error)) *Consequences { 29 c.context.t.Helper() 30 block(c.actions.lastOutput, c.actions.lastError) 31 return c 32 } 33 34 func (c *Consequences) repo() (*v1alpha1.Repository, error) { 35 app, err := c.get() 36 return app, err 37 } 38 39 func (c *Consequences) get() (*v1alpha1.Repository, error) { 40 _, repoClient, _ := fixture.ArgoCDClientset.NewRepoClient() 41 42 repo, _ := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{}) 43 for i := range repo.Items { 44 if repo.Items[i].Repo == c.context.path { 45 return repo.Items[i], nil 46 } 47 } 48 49 return nil, fmt.Errorf("repo not found") 50 } 51 52 func (c *Consequences) Given() *Context { 53 return c.context 54 } 55 56 func (c *Consequences) When() *Actions { 57 return c.actions 58 }