Skip to content

Commit

Permalink
chore: Make e2e tests runnable against remote cluster (argoproj#5895)
Browse files Browse the repository at this point in the history
* chore: Make e2e tests runnable against remote cluster

Signed-off-by: jannfis <[email protected]>

* Fix linter complaint

Signed-off-by: jannfis <[email protected]>

* Revert

Signed-off-by: jannfis <[email protected]>

* Address reviewer comments

Signed-off-by: jannfis <[email protected]>

* Compat with Mac

Signed-off-by: jannfis <[email protected]>

* Revert test setting

Signed-off-by: jannfis <[email protected]>
  • Loading branch information
jannfis authored Apr 7, 2021
1 parent 4f9c500 commit 9afa833
Show file tree
Hide file tree
Showing 37 changed files with 1,050 additions and 76 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ARGOCD_E2E_DEX_PORT?=5556
ARGOCD_E2E_YARN_HOST?=localhost
ARGOCD_E2E_DISABLE_AUTH?=

ARGOCD_E2E_TEST_TIMEOUT?=20m

ARGOCD_IN_CI?=false
ARGOCD_TEST_E2E?=true

Expand Down Expand Up @@ -399,7 +401,7 @@ test-e2e:
test-e2e-local: cli-local
# NO_PROXY ensures all tests don't go out through a proxy if one is configured on the test system
export GO111MODULE=off
ARGOCD_GPG_ENABLED=true NO_PROXY=* ./hack/test.sh -timeout 20m -v ./test/e2e
ARGOCD_GPG_ENABLED=true NO_PROXY=* ./hack/test.sh -timeout $(ARGOCD_E2E_TEST_TIMEOUT) -v ./test/e2e

# Spawns a shell in the test server container for debugging purposes
debug-test-server: test-tools-image
Expand Down
15 changes: 13 additions & 2 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
)

func TestSyncToUnsignedCommit(t *testing.T) {
SkipOnEnv(t, "GPG")
Given(t).
Project("gpg").
Path(guestbookPath).
Expand All @@ -63,6 +64,7 @@ func TestSyncToUnsignedCommit(t *testing.T) {
}

func TestSyncToSignedCommitWithoutKnownKey(t *testing.T) {
SkipOnEnv(t, "GPG")
Given(t).
Project("gpg").
Path(guestbookPath).
Expand All @@ -78,6 +80,7 @@ func TestSyncToSignedCommitWithoutKnownKey(t *testing.T) {
}

func TestSyncToSignedCommitKeyWithKnownKey(t *testing.T) {
SkipOnEnv(t, "GPG")
Given(t).
Project("gpg").
Path(guestbookPath).
Expand Down Expand Up @@ -140,6 +143,7 @@ func TestAppCreation(t *testing.T) {

// demonstrate that we cannot use a standard sync when an immutable field is changed, we must use "force"
func TestImmutableChange(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
text := FailOnErr(Run(".", "kubectl", "get", "service", "-n", "kube-system", "kube-dns", "-o", "jsonpath={.spec.clusterIP}")).(string)
parts := strings.Split(text, ".")
n := rand.Intn(254)
Expand Down Expand Up @@ -600,6 +604,7 @@ func testEdgeCasesApplicationResources(t *testing.T, appPath string, statusCode
}

func TestKsonnetApp(t *testing.T) {
SkipOnEnv(t, "KSONNET")
Given(t).
Path("ksonnet").
Env("prod").
Expand Down Expand Up @@ -1008,6 +1013,7 @@ func TestRevisionHistoryLimit(t *testing.T) {
}

func TestOrphanedResource(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
Given(t).
ProjectSpec(AppProjectSpec{
SourceRepos: []string{"*"},
Expand Down Expand Up @@ -1266,6 +1272,7 @@ func TestCreateAppWithNoNameSpaceWhenRequired2(t *testing.T) {
}

func TestListResource(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
Given(t).
ProjectSpec(AppProjectSpec{
SourceRepos: []string{"*"},
Expand Down Expand Up @@ -1327,10 +1334,13 @@ func TestListResource(t *testing.T) {
// application sync successful
// when application is deleted, --dest-namespace is not deleted
func TestNamespaceAutoCreation(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
updatedNamespace := getNewNamespace(t)
defer func() {
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
assert.NoError(t, err)
if !t.Skipped() {
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
assert.NoError(t, err)
}
}()
Given(t).
Timeout(30).
Expand Down Expand Up @@ -1516,6 +1526,7 @@ definitions:
}

func TestAppLogs(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
Given(t).
Path("guestbook-logs").
When().
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/fixture/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/certs"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/gpgkeys"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/repos"
"github.com/argoproj/argo-cd/v2/util/env"
"github.com/argoproj/argo-cd/v2/util/settings"
)

Expand Down Expand Up @@ -40,7 +41,10 @@ type Context struct {

func Given(t *testing.T) *Context {
fixture.EnsureCleanState(t)
return &Context{t: t, destServer: KubernetesInternalAPIServerAddr, repoURLType: fixture.RepoURLTypeFile, name: fixture.Name(), timeout: 10, project: "default", prune: true}
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
// for any context.
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
return &Context{t: t, destServer: KubernetesInternalAPIServerAddr, repoURLType: fixture.RepoURLTypeFile, name: fixture.Name(), timeout: timeout, project: "default", prune: true}
}

func (c *Context) GPGPublicKeyAdded() *Context {
Expand Down
48 changes: 33 additions & 15 deletions test/e2e/fixture/certs/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,49 @@ import (
func AddCustomCACert() {
caCertPath, err := filepath.Abs("../fixture/certs/argocd-test-ca.crt")
errors.CheckError(err)
args := []string{"cert", "add-tls", "localhost", "--from", caCertPath}
errors.FailOnErr(fixture.RunCli(args...))
args = []string{"cert", "add-tls", "127.0.0.1", "--from", caCertPath}
errors.FailOnErr(fixture.RunCli(args...))
// We need to setup TLS certs according to whether we are running tests
// against a local workload (repositories available as localhost) and
// against remote workloads (repositories available as argocd-e2e-server)
if fixture.IsLocal() {
args := []string{"cert", "add-tls", "localhost", "--from", caCertPath}
errors.FailOnErr(fixture.RunCli(args...))
args = []string{"cert", "add-tls", "127.0.0.1", "--from", caCertPath}
errors.FailOnErr(fixture.RunCli(args...))
certData, err := ioutil.ReadFile(caCertPath)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/localhost", certData, 0644)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/127.0.0.1", certData, 0644)
errors.CheckError(err)
} else {
args := []string{"cert", "add-tls", "argocd-e2e-server", "--from", caCertPath}
errors.FailOnErr(fixture.RunCli(args...))
fixture.RestartAPIServer()
fixture.RestartRepoServer()
}

certData, err := ioutil.ReadFile(caCertPath)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/localhost", certData, 0644)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/tls/127.0.0.1", certData, 0644)
errors.CheckError(err)
}

// AddCustomSSHKnownHostsKeys adds SSH known hosts data to the Argo CD server
// being tested against. The env ARGOCD_E2E_SSH_KNOWN_HOSTS lets you specify
// an optional path to the known hosts file, instead of using the default one.
func AddCustomSSHKnownHostsKeys() {
source := os.Getenv("ARGOCD_E2E_SSH_KNOWN_HOSTS")
if source == "" {
source = "../fixture/testrepos/ssh_known_hosts"
}
knownHostsPath, err := filepath.Abs(source)
errors.CheckError(err)
args := []string{"cert", "add-ssh", "--batch", "--from", knownHostsPath}
args := []string{"cert", "add-ssh", "--upsert", "--batch", "--from", knownHostsPath}
errors.FailOnErr(fixture.RunCli(args...))

knownHostsData, err := ioutil.ReadFile(knownHostsPath)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/ssh/ssh_known_hosts", knownHostsData, 0644)
errors.CheckError(err)
if fixture.IsLocal() {
knownHostsData, err := ioutil.ReadFile(knownHostsPath)
errors.CheckError(err)
err = ioutil.WriteFile(fixture.TmpDir+"/app/config/ssh/ssh_known_hosts", knownHostsData, 0644)
errors.CheckError(err)
} else {
fixture.RestartAPIServer()
fixture.RestartRepoServer()
}
}
Loading

0 comments on commit 9afa833

Please sign in to comment.