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

     1  package repos
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"time"
     7  
     8  	repositorypkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/repository"
     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(repository *v1alpha1.Repository, err error)) *Consequences {
    24  	c.context.t.Helper()
    25  	block(c.repo())
    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) repo() (*v1alpha1.Repository, error) {
    36  	app, err := c.get()
    37  	return app, err
    38  }
    39  
    40  func (c *Consequences) get() (*v1alpha1.Repository, error) {
    41  	_, repoClient, _ := fixture.ArgoCDClientset.NewRepoClient()
    42  
    43  	repo, _ := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
    44  	for i := range repo.Items {
    45  		if repo.Items[i].Repo == c.context.path {
    46  			return repo.Items[i], nil
    47  		}
    48  	}
    49  
    50  	return nil, errors.New("repo 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  }