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

     1  package repos
     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  	path        string
    15  	repoURLType fixture.RepoURLType
    16  	// seconds
    17  	timeout int
    18  	name    string
    19  	project string
    20  }
    21  
    22  func Given(t *testing.T, sameState bool) *Context {
    23  	if !sameState {
    24  		fixture.EnsureCleanState(t)
    25  	}
    26  	// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
    27  	// for any context.
    28  	timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
    29  	return &Context{t: t, repoURLType: fixture.RepoURLTypeFile, name: fixture.Name(), timeout: timeout, project: "default"}
    30  }
    31  
    32  func (c *Context) RepoURLType(urlType fixture.RepoURLType) *Context {
    33  	c.repoURLType = urlType
    34  	return c
    35  }
    36  
    37  func (c *Context) GetName() string {
    38  	return c.name
    39  }
    40  
    41  func (c *Context) Name(name string) *Context {
    42  	c.name = name
    43  	return c
    44  }
    45  
    46  func (c *Context) And(block func()) *Context {
    47  	block()
    48  	return c
    49  }
    50  
    51  func (c *Context) When() *Actions {
    52  	// in case any settings have changed, pause for 1s, not great, but fine
    53  	time.Sleep(1 * time.Second)
    54  	return &Actions{context: c}
    55  }
    56  
    57  func (c *Context) Project(project string) *Context {
    58  	c.project = project
    59  	return c
    60  }