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

     1  package project
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
     8  	"github.com/argoproj/argo-cd/v2/util/env"
     9  )
    10  
    11  // this implements the "given" part of given/when/then
    12  type Context struct {
    13  	t *testing.T
    14  	// seconds
    15  	timeout          int
    16  	name             string
    17  	destination      string
    18  	repos            []string
    19  	sourceNamespaces []string
    20  }
    21  
    22  func Given(t *testing.T) *Context {
    23  	fixture.EnsureCleanState(t)
    24  	return GivenWithSameState(t)
    25  }
    26  
    27  func GivenWithSameState(t *testing.T) *Context {
    28  	// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
    29  	// for any context.
    30  	timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
    31  	return &Context{t: t, name: fixture.Name(), timeout: timeout}
    32  }
    33  
    34  func (c *Context) GetName() string {
    35  	return c.name
    36  }
    37  
    38  func (c *Context) Name(name string) *Context {
    39  	c.name = name
    40  	return c
    41  }
    42  
    43  func (c *Context) Destination(destination string) *Context {
    44  	c.destination = destination
    45  	return c
    46  }
    47  
    48  func (c *Context) SourceRepositories(repos []string) *Context {
    49  	c.repos = repos
    50  	return c
    51  }
    52  
    53  func (c *Context) SourceNamespaces(namespaces []string) *Context {
    54  	c.sourceNamespaces = namespaces
    55  	return c
    56  }
    57  
    58  func (c *Context) And(block func()) *Context {
    59  	block()
    60  	return c
    61  }
    62  
    63  func (c *Context) When() *Actions {
    64  	// in case any settings have changed, pause for 1s, not great, but fine
    65  	time.Sleep(1 * time.Second)
    66  	return &Actions{context: c}
    67  }