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

     1  package project
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
     8  )
     9  
    10  // this implements the "given" part of given/when/then
    11  type Context struct {
    12  	t                          *testing.T
    13  	name                       string
    14  	destination                string
    15  	destinationServiceAccounts []string
    16  	repos                      []string
    17  	sourceNamespaces           []string
    18  }
    19  
    20  func Given(t *testing.T) *Context {
    21  	t.Helper()
    22  	fixture.EnsureCleanState(t)
    23  	return GivenWithSameState(t)
    24  }
    25  
    26  func GivenWithSameState(t *testing.T) *Context {
    27  	t.Helper()
    28  	return &Context{t: t, name: fixture.Name()}
    29  }
    30  
    31  func (c *Context) GetName() string {
    32  	return c.name
    33  }
    34  
    35  func (c *Context) Name(name string) *Context {
    36  	c.name = name
    37  	return c
    38  }
    39  
    40  func (c *Context) Destination(destination string) *Context {
    41  	c.destination = destination
    42  	return c
    43  }
    44  
    45  func (c *Context) DestinationServiceAccounts(destinationServiceAccounts []string) *Context {
    46  	c.destinationServiceAccounts = destinationServiceAccounts
    47  	return c
    48  }
    49  
    50  func (c *Context) SourceRepositories(repos []string) *Context {
    51  	c.repos = repos
    52  	return c
    53  }
    54  
    55  func (c *Context) SourceNamespaces(namespaces []string) *Context {
    56  	c.sourceNamespaces = namespaces
    57  	return c
    58  }
    59  
    60  func (c *Context) And(block func()) *Context {
    61  	block()
    62  	return c
    63  }
    64  
    65  func (c *Context) When() *Actions {
    66  	time.Sleep(fixture.WhenThenSleepInterval)
    67  	return &Actions{context: c}
    68  }