From ac51f6682919d929dedce5eea02a1cf1eaf9a6d4 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Thu, 6 Jun 2019 15:50:10 -0700 Subject: [PATCH] Name e2e apps after the test they run for, rather than random ID. (#1698) --- test/e2e/app_management_test.go | 2 +- test/e2e/fixture/app/consequences.go | 2 ++ test/e2e/fixture/app/context.go | 2 +- test/e2e/fixture/fixture.go | 8 ++++---- test/e2e/fixture/util.go | 15 +++++++++++++++ test/e2e/project_management_test.go | 16 ++++++++-------- test/e2e/repo_creds_test.go | 6 +++--- 7 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 test/e2e/fixture/util.go diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index c29f9ca83d..23b67dcdd5 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -446,7 +446,7 @@ func TestSyncResourceByLabel(t *testing.T) { } func TestPermissions(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) appName := fixture.Name() _, err := fixture.RunCli("proj", "create", "test") assert.NoError(t, err) diff --git a/test/e2e/fixture/app/consequences.go b/test/e2e/fixture/app/consequences.go index 71d2b7c08a..d7e73407b5 100644 --- a/test/e2e/fixture/app/consequences.go +++ b/test/e2e/fixture/app/consequences.go @@ -18,6 +18,8 @@ type Consequences struct { } func (c *Consequences) Expect(e Expectation) *Consequences { + // this invocation makes sure this func is not reported as the cause of the failure - we are a "test helper" + c.context.t.Helper() var message string var state state for start := time.Now(); time.Since(start) < 15*time.Second; time.Sleep(3 * time.Second) { diff --git a/test/e2e/fixture/app/context.go b/test/e2e/fixture/app/context.go index b9bfc8dcaa..a800a2058f 100644 --- a/test/e2e/fixture/app/context.go +++ b/test/e2e/fixture/app/context.go @@ -21,7 +21,7 @@ type Context struct { } func Given(t *testing.T) *Context { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) return &Context{t: t, destServer: KubernetesInternalAPIServerAddr, name: fixture.Name(), prune: true} } diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index 867cbbb7f4..57a69cca9c 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -8,6 +8,7 @@ import ( "path" "path/filepath" "strings" + "testing" "time" jsonpatch "github.com/evanphx/json-patch" @@ -24,7 +25,6 @@ import ( appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned" "github.com/argoproj/argo-cd/util" grpcutil "github.com/argoproj/argo-cd/util/grpc" - "github.com/argoproj/argo-cd/util/rand" "github.com/argoproj/argo-cd/util/settings" ) @@ -101,7 +101,7 @@ func init() { } func Name() string { - return fmt.Sprintf("argocd-e2e-%s", id) + return id } func repoDirectory() string { @@ -130,7 +130,7 @@ func CreateSecret(username, password string) string { return secretName } -func EnsureCleanState() { +func EnsureCleanState(t *testing.T) { start := time.Now() @@ -169,7 +169,7 @@ func EnsureCleanState() { CheckError(os.RemoveAll(tmpDir)) // new random ID - id = strings.ToLower(rand.RandString(5)) + id = dnsFriendly(t.Name()) repoUrl = fmt.Sprintf("file:///%s", repoDirectory()) // create tmp dir diff --git a/test/e2e/fixture/util.go b/test/e2e/fixture/util.go new file mode 100644 index 0000000000..443692b6b4 --- /dev/null +++ b/test/e2e/fixture/util.go @@ -0,0 +1,15 @@ +package fixture + +import ( + "regexp" + "strings" +) + +var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") +var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])") + +func dnsFriendly(str string) string { + snake := matchFirstCap.ReplaceAllString(str, "${1}-${2}") + snake = matchAllCap.ReplaceAllString(snake, "${1}-${2}") + return strings.ToLower(snake) +} diff --git a/test/e2e/project_management_test.go b/test/e2e/project_management_test.go index f0e0a64066..07396777ea 100644 --- a/test/e2e/project_management_test.go +++ b/test/e2e/project_management_test.go @@ -37,7 +37,7 @@ func assertProjHasEvent(t *testing.T, a *v1alpha1.AppProject, message string, re } func TestProjectCreation(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + fixture.Name() _, err := fixture.RunCli("proj", "create", projectName, @@ -65,7 +65,7 @@ func TestProjectCreation(t *testing.T) { } func TestProjectDeletion(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}) @@ -80,7 +80,7 @@ func TestProjectDeletion(t *testing.T) { } func TestSetProject(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}) @@ -106,7 +106,7 @@ func TestSetProject(t *testing.T) { } func TestAddProjectDestination(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}) @@ -141,7 +141,7 @@ func TestAddProjectDestination(t *testing.T) { } func TestRemoveProjectDestination(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ @@ -184,7 +184,7 @@ func TestRemoveProjectDestination(t *testing.T) { } func TestAddProjectSource(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}) @@ -210,7 +210,7 @@ func TestAddProjectSource(t *testing.T) { } func TestRemoveProjectSource(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) _, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Create(&v1alpha1.AppProject{ @@ -237,7 +237,7 @@ func TestRemoveProjectSource(t *testing.T) { } func TestUseJWTToken(t *testing.T) { - fixture.EnsureCleanState() + fixture.EnsureCleanState(t) projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10) appName := "app-" + strconv.FormatInt(time.Now().Unix(), 10) diff --git a/test/e2e/repo_creds_test.go b/test/e2e/repo_creds_test.go index e9618cfd6b..dd1f445768 100644 --- a/test/e2e/repo_creds_test.go +++ b/test/e2e/repo_creds_test.go @@ -14,7 +14,7 @@ const accessToken = "B5sBDeoqAVUouoHkrovy" const appPath = "child-base" // make sure you cannot create an app from a private repo without set-up -func TestCannotAddAppFromPrivateRepoWithOutConfig(t *testing.T) { +func TestCannotAddAppFromPrivateRepoWithoutCfg(t *testing.T) { Given(t). Repo(repoUrl). Path(appPath). @@ -25,7 +25,7 @@ func TestCannotAddAppFromPrivateRepoWithOutConfig(t *testing.T) { } // make sure you can create an app from a private repo, if the repo is set-up in the CM -func TestCanAddAppFromPrivateRepoWithRepoConfig(t *testing.T) { +func TestCanAddAppFromPrivateRepoWithRepoCfg(t *testing.T) { Given(t). Repo(repoUrl). Path(appPath). @@ -40,7 +40,7 @@ func TestCanAddAppFromPrivateRepoWithRepoConfig(t *testing.T) { } // make sure you can create an app from a private repo, if the creds are set-up in the CM -func TestCanAddAppFromPrivateRepoWithCredConfig(t *testing.T) { +func TestCanAddAppFromPrivateRepoWithCredCfg(t *testing.T) { Given(t). Repo(repoUrl).