github.com/argoproj/argo-cd/v2@v2.10.9/test/e2e/fixture/cluster/context.go (about) 1 package cluster 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 project string 18 server string 19 upsert bool 20 namespaces []string 21 bearerToken string 22 } 23 24 func Given(t *testing.T) *Context { 25 fixture.EnsureCleanState(t) 26 return GivenWithSameState(t) 27 } 28 29 func GivenWithSameState(t *testing.T) *Context { 30 // ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout 31 // for any context. 32 timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180) 33 return &Context{t: t, name: fixture.Name(), timeout: timeout, project: "default"} 34 } 35 36 func (c *Context) GetName() string { 37 return c.name 38 } 39 40 func (c *Context) Name(name string) *Context { 41 c.name = name 42 return c 43 } 44 45 func (c *Context) Server(server string) *Context { 46 c.server = server 47 return c 48 } 49 50 func (c *Context) Namespaces(namespaces []string) *Context { 51 c.namespaces = namespaces 52 return c 53 } 54 55 func (c *Context) And(block func()) *Context { 56 block() 57 return c 58 } 59 60 func (c *Context) When() *Actions { 61 // in case any settings have changed, pause for 1s, not great, but fine 62 time.Sleep(1 * time.Second) 63 return &Actions{context: c} 64 } 65 66 func (c *Context) Project(project string) *Context { 67 c.project = project 68 return c 69 } 70 71 func (c *Context) BearerToken(bearerToken string) *Context { 72 c.bearerToken = bearerToken 73 return c 74 } 75 76 func (c *Context) Upsert(upsert bool) *Context { 77 c.upsert = upsert 78 return c 79 }