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