github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/fixture/cluster/consequences.go (about)

     1  package cluster
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	clusterpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
     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(cluster *v1alpha1.Cluster, err error)) *Consequences {
    23  	c.context.t.Helper()
    24  	block(c.cluster())
    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) cluster() (*v1alpha1.Cluster, error) {
    35  	app, err := c.get()
    36  	return app, err
    37  }
    38  
    39  func (c *Consequences) get() (*v1alpha1.Cluster, error) {
    40  	_, clusterClient, _ := fixture.ArgoCDClientset.NewClusterClient()
    41  
    42  	cluster, _ := clusterClient.List(context.Background(), &clusterpkg.ClusterQuery{})
    43  	for i := range cluster.Items {
    44  		if cluster.Items[i].Server == c.context.server {
    45  			return &cluster.Items[i], nil
    46  		}
    47  	}
    48  
    49  	return nil, fmt.Errorf("cluster 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  }