Name e2e apps after the test they run for, rather than random ID. (#1698)

This commit is contained in:
Alex Collins 2019-06-06 15:50:10 -07:00 committed by GitHub
parent bc7bbb9dbc
commit ac51f66829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 17 deletions

View file

@ -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)

View file

@ -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) {

View file

@ -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}
}

View file

@ -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

15
test/e2e/fixture/util.go Normal file
View file

@ -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)
}

View file

@ -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)

View file

@ -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).