github.com/argoproj/argo-cd@v1.8.7/test/e2e/fixture/app/context.go (about) 1 package app 2 3 import ( 4 "testing" 5 "time" 6 7 . "github.com/argoproj/argo-cd/common" 8 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" 9 "github.com/argoproj/argo-cd/test/e2e/fixture" 10 "github.com/argoproj/argo-cd/test/e2e/fixture/certs" 11 "github.com/argoproj/argo-cd/test/e2e/fixture/gpgkeys" 12 "github.com/argoproj/argo-cd/test/e2e/fixture/repos" 13 "github.com/argoproj/argo-cd/util/settings" 14 ) 15 16 // this implements the "given" part of given/when/then 17 type Context struct { 18 t *testing.T 19 path string 20 chart string 21 repoURLType fixture.RepoURLType 22 // seconds 23 timeout int 24 name string 25 destServer string 26 env string 27 parameters []string 28 namePrefix string 29 nameSuffix string 30 resource string 31 prune bool 32 configManagementPlugin string 33 async bool 34 localPath string 35 project string 36 revision string 37 force bool 38 directoryRecurse bool 39 } 40 41 func Given(t *testing.T) *Context { 42 fixture.EnsureCleanState(t) 43 return &Context{t: t, destServer: KubernetesInternalAPIServerAddr, repoURLType: fixture.RepoURLTypeFile, name: fixture.Name(), timeout: 10, project: "default", prune: true} 44 } 45 46 func (c *Context) GPGPublicKeyAdded() *Context { 47 gpgkeys.AddGPGPublicKey() 48 return c 49 } 50 51 func (c *Context) GPGPublicKeyRemoved() *Context { 52 gpgkeys.DeleteGPGPublicKey() 53 return c 54 } 55 56 func (c *Context) CustomCACertAdded() *Context { 57 certs.AddCustomCACert() 58 return c 59 } 60 61 func (c *Context) CustomSSHKnownHostsAdded() *Context { 62 certs.AddCustomSSHKnownHostsKeys() 63 return c 64 } 65 66 func (c *Context) HTTPSRepoURLAdded(withCreds bool) *Context { 67 repos.AddHTTPSRepo(false, withCreds, fixture.RepoURLTypeHTTPS) 68 return c 69 } 70 71 func (c *Context) HTTPSInsecureRepoURLAdded(withCreds bool) *Context { 72 repos.AddHTTPSRepo(true, withCreds, fixture.RepoURLTypeHTTPS) 73 return c 74 } 75 76 func (c *Context) HTTPSInsecureRepoURLWithClientCertAdded() *Context { 77 repos.AddHTTPSRepoClientCert(true) 78 return c 79 } 80 81 func (c *Context) HTTPSRepoURLWithClientCertAdded() *Context { 82 repos.AddHTTPSRepoClientCert(false) 83 return c 84 } 85 86 func (c *Context) SubmoduleHTTPSRepoURLAdded(withCreds bool) *Context { 87 fixture.CreateSubmoduleRepos("https") 88 repos.AddHTTPSRepo(false, withCreds, fixture.RepoURLTypeHTTPSSubmoduleParent) 89 return c 90 } 91 92 func (c *Context) SSHRepoURLAdded(withCreds bool) *Context { 93 repos.AddSSHRepo(false, withCreds, fixture.RepoURLTypeSSH) 94 return c 95 } 96 97 func (c *Context) SSHInsecureRepoURLAdded(withCreds bool) *Context { 98 repos.AddSSHRepo(true, withCreds, fixture.RepoURLTypeSSH) 99 return c 100 } 101 102 func (c *Context) SubmoduleSSHRepoURLAdded(withCreds bool) *Context { 103 fixture.CreateSubmoduleRepos("ssh") 104 repos.AddSSHRepo(false, withCreds, fixture.RepoURLTypeSSHSubmoduleParent) 105 return c 106 } 107 108 func (c *Context) HelmRepoAdded(name string) *Context { 109 repos.AddHelmRepo(name) 110 return c 111 } 112 113 func (c *Context) HTTPSCredentialsUserPassAdded() *Context { 114 repos.AddHTTPSCredentialsUserPass() 115 return c 116 } 117 118 func (c *Context) HTTPSCredentialsTLSClientCertAdded() *Context { 119 repos.AddHTTPSCredentialsTLSClientCert() 120 return c 121 } 122 123 func (c *Context) SSHCredentialsAdded() *Context { 124 repos.AddSSHCredentials() 125 return c 126 } 127 128 func (c *Context) ProjectSpec(spec v1alpha1.AppProjectSpec) *Context { 129 fixture.SetProjectSpec(c.project, spec) 130 return c 131 } 132 133 func (c *Context) RepoURLType(urlType fixture.RepoURLType) *Context { 134 c.repoURLType = urlType 135 return c 136 } 137 138 func (c *Context) GetName() string { 139 return c.name 140 } 141 142 func (c *Context) Name(name string) *Context { 143 c.name = name 144 return c 145 } 146 147 func (c *Context) Path(path string) *Context { 148 c.path = path 149 return c 150 } 151 152 func (c *Context) Recurse() *Context { 153 c.directoryRecurse = true 154 return c 155 } 156 157 func (c *Context) Chart(chart string) *Context { 158 c.chart = chart 159 return c 160 } 161 162 func (c *Context) Revision(revision string) *Context { 163 c.revision = revision 164 return c 165 } 166 167 func (c *Context) Timeout(timeout int) *Context { 168 c.timeout = timeout 169 return c 170 } 171 172 func (c *Context) DestServer(destServer string) *Context { 173 c.destServer = destServer 174 return c 175 } 176 177 func (c *Context) Env(env string) *Context { 178 c.env = env 179 return c 180 } 181 182 func (c *Context) Parameter(parameter string) *Context { 183 c.parameters = append(c.parameters, parameter) 184 return c 185 } 186 187 // group:kind:name 188 func (c *Context) SelectedResource(resource string) *Context { 189 c.resource = resource 190 return c 191 } 192 193 func (c *Context) NamePrefix(namePrefix string) *Context { 194 c.namePrefix = namePrefix 195 return c 196 } 197 198 func (c *Context) NameSuffix(nameSuffix string) *Context { 199 c.nameSuffix = nameSuffix 200 return c 201 } 202 203 func (c *Context) ResourceOverrides(overrides map[string]v1alpha1.ResourceOverride) *Context { 204 fixture.SetResourceOverrides(overrides) 205 return c 206 } 207 208 func (c *Context) ResourceFilter(filter settings.ResourcesFilter) *Context { 209 fixture.SetResourceFilter(filter) 210 return c 211 } 212 213 // this both configures the plugin, but forces use of it 214 func (c *Context) ConfigManagementPlugin(plugin v1alpha1.ConfigManagementPlugin) *Context { 215 fixture.SetConfigManagementPlugins(plugin) 216 c.configManagementPlugin = plugin.Name 217 return c 218 } 219 220 func (c *Context) And(block func()) *Context { 221 block() 222 return c 223 } 224 225 func (c *Context) When() *Actions { 226 // in case any settings have changed, pause for 1s, not great, but fine 227 time.Sleep(1 * time.Second) 228 return &Actions{context: c} 229 } 230 231 func (c *Context) Sleep(seconds time.Duration) *Context { 232 time.Sleep(seconds * time.Second) 233 return c 234 } 235 236 func (c *Context) Prune(prune bool) *Context { 237 c.prune = prune 238 return c 239 } 240 241 func (c *Context) Async(async bool) *Context { 242 c.async = async 243 return c 244 } 245 246 func (c *Context) LocalPath(localPath string) *Context { 247 c.localPath = localPath 248 return c 249 } 250 251 func (c *Context) Project(project string) *Context { 252 c.project = project 253 return c 254 } 255 256 func (c *Context) Force() *Context { 257 c.force = true 258 return c 259 }