test(e2e): unstable CMP e2e test when running locally (#25752)

Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
This commit is contained in:
Alexandre Gaudreault
2026-01-05 15:18:26 -05:00
committed by GitHub
parent 884b639e1e
commit f8899ee310
6 changed files with 118 additions and 102 deletions

View File

@@ -507,6 +507,7 @@ start-e2e-local: mod-vendor-local dep-ui-local cli-local
ARGOCD_GPG_ENABLED=$(ARGOCD_GPG_ENABLED) \ ARGOCD_GPG_ENABLED=$(ARGOCD_GPG_ENABLED) \
ARGOCD_PLUGINCONFIGFILEPATH=/tmp/argo-e2e/app/config/plugin \ ARGOCD_PLUGINCONFIGFILEPATH=/tmp/argo-e2e/app/config/plugin \
ARGOCD_PLUGINSOCKFILEPATH=/tmp/argo-e2e/app/config/plugin \ ARGOCD_PLUGINSOCKFILEPATH=/tmp/argo-e2e/app/config/plugin \
ARGOCD_GIT_CONFIG=$(PWD)/test/e2e/fixture/gitconfig \
ARGOCD_E2E_DISABLE_AUTH=false \ ARGOCD_E2E_DISABLE_AUTH=false \
ARGOCD_ZJWT_FEATURE_FLAG=always \ ARGOCD_ZJWT_FEATURE_FLAG=always \
ARGOCD_IN_CI=$(ARGOCD_IN_CI) \ ARGOCD_IN_CI=$(ARGOCD_IN_CI) \

View File

@@ -2,7 +2,7 @@ controller: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run
api-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/api-server} FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-server $COMMAND --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --otlp-address=${ARGOCD_OTLP_ADDRESS} --application-namespaces=${ARGOCD_APPLICATION_NAMESPACES:-''} --hydrator-enabled=${ARGOCD_HYDRATOR_ENABLED:='false'}" api-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/api-server} FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-server $COMMAND --loglevel debug --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --disable-auth=${ARGOCD_E2E_DISABLE_AUTH:-'true'} --insecure --dex-server http://localhost:${ARGOCD_E2E_DEX_PORT:-5556} --repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081} --port ${ARGOCD_E2E_APISERVER_PORT:-8080} --otlp-address=${ARGOCD_OTLP_ADDRESS} --application-namespaces=${ARGOCD_APPLICATION_NAMESPACES:-''} --hydrator-enabled=${ARGOCD_HYDRATOR_ENABLED:='false'}"
dex: sh -c "ARGOCD_BINARY_NAME=argocd-dex go run github.com/argoproj/argo-cd/v3/cmd gendexcfg -o `pwd`/dist/dex.yaml && (test -f dist/dex.yaml || { echo 'Failed to generate dex configuration'; exit 1; }) && docker run --rm -p ${ARGOCD_E2E_DEX_PORT:-5556}:${ARGOCD_E2E_DEX_PORT:-5556} -v `pwd`/dist/dex.yaml:/dex.yaml ghcr.io/dexidp/dex:$(grep "image: ghcr.io/dexidp/dex" manifests/base/dex/argocd-dex-server-deployment.yaml | cut -d':' -f3) dex serve /dex.yaml" dex: sh -c "ARGOCD_BINARY_NAME=argocd-dex go run github.com/argoproj/argo-cd/v3/cmd gendexcfg -o `pwd`/dist/dex.yaml && (test -f dist/dex.yaml || { echo 'Failed to generate dex configuration'; exit 1; }) && docker run --rm -p ${ARGOCD_E2E_DEX_PORT:-5556}:${ARGOCD_E2E_DEX_PORT:-5556} -v `pwd`/dist/dex.yaml:/dex.yaml ghcr.io/dexidp/dex:$(grep "image: ghcr.io/dexidp/dex" manifests/base/dex/argocd-dex-server-deployment.yaml | cut -d':' -f3) dex serve /dex.yaml"
redis: hack/start-redis-with-password.sh redis: hack/start-redis-with-password.sh
repo-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/repo-server} FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_PLUGINSOCKFILEPATH=${ARGOCD_PLUGINSOCKFILEPATH:-./test/cmp} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-repo-server ARGOCD_GPG_ENABLED=${ARGOCD_GPG_ENABLED:-false} $COMMAND --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --otlp-address=${ARGOCD_OTLP_ADDRESS}" repo-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "export PATH=./dist:\$PATH && [ -n \"\$ARGOCD_GIT_CONFIG\" ] && export GIT_CONFIG_GLOBAL=\$ARGOCD_GIT_CONFIG && export GIT_CONFIG_NOSYSTEM=1; GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/repo-server} FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_GNUPGHOME=${ARGOCD_GNUPGHOME:-/tmp/argocd-local/gpg/keys} ARGOCD_PLUGINSOCKFILEPATH=${ARGOCD_PLUGINSOCKFILEPATH:-./test/cmp} ARGOCD_GPG_DATA_PATH=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-repo-server ARGOCD_GPG_ENABLED=${ARGOCD_GPG_ENABLED:-false} $COMMAND --loglevel debug --port ${ARGOCD_E2E_REPOSERVER_PORT:-8081} --redis localhost:${ARGOCD_E2E_REDIS_PORT:-6379} --otlp-address=${ARGOCD_OTLP_ADDRESS}"
cmp-server: [ "$ARGOCD_E2E_TEST" = 'true' ] && exit 0 || [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_BINARY_NAME=argocd-cmp-server ARGOCD_PLUGINSOCKFILEPATH=${ARGOCD_PLUGINSOCKFILEPATH:-./test/cmp} $COMMAND --config-dir-path ./test/cmp --loglevel debug --otlp-address=${ARGOCD_OTLP_ADDRESS}" cmp-server: [ "$ARGOCD_E2E_TEST" = 'true' ] && exit 0 || [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "FORCE_LOG_COLORS=1 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_BINARY_NAME=argocd-cmp-server ARGOCD_PLUGINSOCKFILEPATH=${ARGOCD_PLUGINSOCKFILEPATH:-./test/cmp} $COMMAND --config-dir-path ./test/cmp --loglevel debug --otlp-address=${ARGOCD_OTLP_ADDRESS}"
commit-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/commit-server} FORCE_LOG_COLORS=1 ARGOCD_BINARY_NAME=argocd-commit-server $COMMAND --loglevel debug --port ${ARGOCD_E2E_COMMITSERVER_PORT:-8086}" commit-server: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/commit-server} FORCE_LOG_COLORS=1 ARGOCD_BINARY_NAME=argocd-commit-server $COMMAND --loglevel debug --port ${ARGOCD_E2E_COMMITSERVER_PORT:-8086}"
ui: sh -c 'cd ui && ${ARGOCD_E2E_YARN_CMD:-yarn} start' ui: sh -c 'cd ui && ${ARGOCD_E2E_YARN_CMD:-yarn} start'
@@ -11,4 +11,4 @@ helm-registry: test/fixture/testrepos/start-helm-registry.sh
oci-registry: test/fixture/testrepos/start-authenticated-helm-registry.sh oci-registry: test/fixture/testrepos/start-authenticated-helm-registry.sh
dev-mounter: [ "$ARGOCD_E2E_TEST" != "true" ] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source} dev-mounter: [ "$ARGOCD_E2E_TEST" != "true" ] && go run hack/dev-mounter/main.go --configmap argocd-ssh-known-hosts-cm=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} --configmap argocd-tls-certs-cm=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} --configmap argocd-gpg-keys-cm=${ARGOCD_GPG_DATA_PATH:-/tmp/argocd-local/gpg/source}
applicationset-controller: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/applicationset-controller} FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-applicationset-controller $COMMAND --loglevel debug --metrics-addr localhost:12345 --probe-addr localhost:12346 --argocd-repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}" applicationset-controller: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/applicationset-controller} FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_SSH_DATA_PATH=${ARGOCD_SSH_DATA_PATH:-/tmp/argocd-local/ssh} ARGOCD_BINARY_NAME=argocd-applicationset-controller $COMMAND --loglevel debug --metrics-addr localhost:12345 --probe-addr localhost:12346 --argocd-repo-server localhost:${ARGOCD_E2E_REPOSERVER_PORT:-8081}"
notification: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/notification} FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_BINARY_NAME=argocd-notifications $COMMAND --loglevel debug --application-namespaces=${ARGOCD_APPLICATION_NAMESPACES:-''} --self-service-notification-enabled=${ARGOCD_NOTIFICATION_CONTROLLER_SELF_SERVICE_NOTIFICATION_ENABLED:-'false'}" notification: [ "$BIN_MODE" = 'true' ] && COMMAND=./dist/argocd || COMMAND='go run ./cmd/main.go' && sh -c "GOCOVERDIR=${ARGOCD_COVERAGE_DIR:-/tmp/coverage/notification} FORCE_LOG_COLORS=4 ARGOCD_FAKE_IN_CLUSTER=true ARGOCD_TLS_DATA_PATH=${ARGOCD_TLS_DATA_PATH:-/tmp/argocd-local/tls} ARGOCD_BINARY_NAME=argocd-notifications $COMMAND --loglevel debug --application-namespaces=${ARGOCD_APPLICATION_NAMESPACES:-''} --self-service-notification-enabled=${ARGOCD_NOTIFICATION_CONTROLLER_SELF_SERVICE_NOTIFICATION_ENABLED:-'false'}"

View File

@@ -1,12 +1,10 @@
package e2e package e2e
import ( import (
"os"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"testing" "testing"
"time"
"github.com/argoproj/gitops-engine/pkg/health" "github.com/argoproj/gitops-engine/pkg/health"
. "github.com/argoproj/gitops-engine/pkg/sync/common" . "github.com/argoproj/gitops-engine/pkg/sync/common"
@@ -23,11 +21,7 @@ import (
func TestCustomToolWithGitCreds(t *testing.T) { func TestCustomToolWithGitCreds(t *testing.T) {
ctx := Given(t) ctx := Given(t)
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-gitcreds").
go startCMPServer(t, "./testdata/cmp-gitcreds")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
CustomCACertAdded(). CustomCACertAdded().
// add the private repo with credentials // add the private repo with credentials
HTTPSRepoURLAdded(true). HTTPSRepoURLAdded(true).
@@ -51,11 +45,7 @@ func TestCustomToolWithGitCreds(t *testing.T) {
func TestCustomToolWithGitCredsTemplate(t *testing.T) { func TestCustomToolWithGitCredsTemplate(t *testing.T) {
ctx := Given(t) ctx := Given(t)
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-gitcredstemplate").
go startCMPServer(t, "./testdata/cmp-gitcredstemplate")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
CustomCACertAdded(). CustomCACertAdded().
// add the git creds template // add the git creds template
HTTPSCredentialsUserPassAdded(). HTTPSCredentialsUserPassAdded().
@@ -92,11 +82,7 @@ func TestCustomToolWithSSHGitCreds(t *testing.T) {
ctx := Given(t) ctx := Given(t)
// path does not matter, we ignore it // path does not matter, we ignore it
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-gitsshcreds").
go startCMPServer(t, "./testdata/cmp-gitsshcreds")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
// add the private repo with ssh credentials // add the private repo with ssh credentials
CustomSSHKnownHostsAdded(). CustomSSHKnownHostsAdded().
SSHRepoURLAdded(true). SSHRepoURLAdded(true).
@@ -126,11 +112,7 @@ func TestCustomToolWithSSHGitCredsDisabled(t *testing.T) {
ctx := Given(t) ctx := Given(t)
// path does not matter, we ignore it // path does not matter, we ignore it
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-gitsshcreds-disable-provide").
go startCMPServer(t, "./testdata/cmp-gitsshcreds-disable-provide")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
CustomCACertAdded(). CustomCACertAdded().
// add the private repo with ssh credentials // add the private repo with ssh credentials
CustomSSHKnownHostsAdded(). CustomSSHKnownHostsAdded().
@@ -150,11 +132,7 @@ func TestCustomToolWithSSHGitCredsDisabled(t *testing.T) {
func TestCustomToolWithEnv(t *testing.T) { func TestCustomToolWithEnv(t *testing.T) {
ctx := Given(t) ctx := Given(t)
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-fileName").
go startCMPServer(t, "./testdata/cmp-fileName")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
// does not matter what the path is // does not matter what the path is
Path("cmp-fileName"). Path("cmp-fileName").
When(). When().
@@ -211,11 +189,7 @@ func TestCustomToolSyncAndDiffLocal(t *testing.T) {
ctx := Given(t) ctx := Given(t)
appPath := filepath.Join(testdataPath, "guestbook") appPath := filepath.Join(testdataPath, "guestbook")
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-kustomize").
go startCMPServer(t, "./testdata/cmp-kustomize")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
// does not matter what the path is // does not matter what the path is
Path("guestbook"). Path("guestbook").
When(). When().
@@ -233,29 +207,11 @@ func TestCustomToolSyncAndDiffLocal(t *testing.T) {
}) })
} }
func startCMPServer(t *testing.T, configFile string) {
t.Helper()
pluginSockFilePath := fixture.TmpDir + fixture.PluginSockFilePath
t.Setenv("ARGOCD_BINARY_NAME", "argocd-cmp-server")
// ARGOCD_PLUGINSOCKFILEPATH should be set as the same value as repo server env var
t.Setenv("ARGOCD_PLUGINSOCKFILEPATH", pluginSockFilePath)
if _, err := os.Stat(pluginSockFilePath); os.IsNotExist(err) {
// path/to/whatever does not exist
err := os.Mkdir(pluginSockFilePath, 0o700)
require.NoError(t, err)
}
errors.NewHandler(t).FailOnErr(fixture.RunWithStdin("", "", "../../dist/argocd", "--config-dir-path", configFile))
}
// Discover by fileName // Discover by fileName
func TestCMPDiscoverWithFileName(t *testing.T) { func TestCMPDiscoverWithFileName(t *testing.T) {
pluginName := "cmp-fileName" pluginName := "cmp-fileName"
Given(t). Given(t).
And(func() { RunningCMPServer("./testdata/cmp-fileName").
go startCMPServer(t, "./testdata/cmp-fileName")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path(pluginName + "/subdir"). Path(pluginName + "/subdir").
When(). When().
CreateApp(). CreateApp().
@@ -269,11 +225,7 @@ func TestCMPDiscoverWithFileName(t *testing.T) {
// Discover by Find glob // Discover by Find glob
func TestCMPDiscoverWithFindGlob(t *testing.T) { func TestCMPDiscoverWithFindGlob(t *testing.T) {
Given(t). Given(t).
And(func() { RunningCMPServer("./testdata/cmp-find-glob").
go startCMPServer(t, "./testdata/cmp-find-glob")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook"). Path("guestbook").
When(). When().
CreateApp(). CreateApp().
@@ -287,11 +239,7 @@ func TestCMPDiscoverWithFindGlob(t *testing.T) {
// Discover by Plugin Name // Discover by Plugin Name
func TestCMPDiscoverWithPluginName(t *testing.T) { func TestCMPDiscoverWithPluginName(t *testing.T) {
Given(t). Given(t).
And(func() { RunningCMPServer("./testdata/cmp-find-glob").
go startCMPServer(t, "./testdata/cmp-find-glob")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook"). Path("guestbook").
When(). When().
CreateFromFile(func(app *Application) { CreateFromFile(func(app *Application) {
@@ -310,11 +258,7 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) {
pluginName := "cmp-find-command" pluginName := "cmp-find-command"
ctx := Given(t) ctx := Given(t)
ctx. ctx.
And(func() { RunningCMPServer("./testdata/cmp-find-command").
go startCMPServer(t, "./testdata/cmp-find-command")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path(pluginName). Path(pluginName).
When(). When().
CreateApp(). CreateApp().
@@ -349,12 +293,9 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) {
} }
func TestPruneResourceFromCMP(t *testing.T) { func TestPruneResourceFromCMP(t *testing.T) {
Given(t). ctx := Given(t)
And(func() { ctx.
go startCMPServer(t, "./testdata/cmp-find-glob") RunningCMPServer("./testdata/cmp-find-glob").
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook"). Path("guestbook").
When(). When().
CreateApp(). CreateApp().
@@ -373,11 +314,7 @@ func TestPruneResourceFromCMP(t *testing.T) {
func TestPreserveFileModeForCMP(t *testing.T) { func TestPreserveFileModeForCMP(t *testing.T) {
Given(t). Given(t).
And(func() { RunningCMPServer("./testdata/cmp-preserve-file-mode").
go startCMPServer(t, "./testdata/cmp-preserve-file-mode")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("cmp-preserve-file-mode"). Path("cmp-preserve-file-mode").
When(). When().
CreateFromFile(func(app *Application) { CreateFromFile(func(app *Application) {
@@ -393,11 +330,7 @@ func TestPreserveFileModeForCMP(t *testing.T) {
func TestCMPWithSymlinkPartialFiles(t *testing.T) { func TestCMPWithSymlinkPartialFiles(t *testing.T) {
Given(t, fixture.WithTestData("testdata2")). Given(t, fixture.WithTestData("testdata2")).
And(func() { RunningCMPServer("./testdata2/cmp-symlink").
go startCMPServer(t, "./testdata2/cmp-symlink")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook-partial-symlink-files"). Path("guestbook-partial-symlink-files").
When(). When().
CreateApp(). CreateApp().
@@ -410,11 +343,7 @@ func TestCMPWithSymlinkPartialFiles(t *testing.T) {
func TestCMPWithSymlinkFiles(t *testing.T) { func TestCMPWithSymlinkFiles(t *testing.T) {
Given(t, fixture.WithTestData("testdata2")). Given(t, fixture.WithTestData("testdata2")).
And(func() { RunningCMPServer("./testdata2/cmp-symlink").
go startCMPServer(t, "./testdata2/cmp-symlink")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook-symlink-files"). Path("guestbook-symlink-files").
When(). When().
CreateApp(). CreateApp().
@@ -427,11 +356,7 @@ func TestCMPWithSymlinkFiles(t *testing.T) {
func TestCMPWithSymlinkFolder(t *testing.T) { func TestCMPWithSymlinkFolder(t *testing.T) {
Given(t, fixture.WithTestData("testdata2")). Given(t, fixture.WithTestData("testdata2")).
And(func() { RunningCMPServer("./testdata2/cmp-symlink").
go startCMPServer(t, "./testdata2/cmp-symlink")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
Path("guestbook-symlink-folder"). Path("guestbook-symlink-folder").
When(). When().
CreateApp(). CreateApp().

View File

@@ -0,0 +1,87 @@
package app
import (
"os"
"path"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/argoproj/argo-cd/v3/cmpserver/plugin"
"github.com/argoproj/argo-cd/v3/test/e2e/fixture"
"github.com/argoproj/argo-cd/v3/util/errors"
)
// RunningCMPServer starts a CMP server with the given config directory and waits for it to be ready.
// It blocks until the CMP socket is created or times out after 10 seconds.
func (c *Context) RunningCMPServer(configFile string) *Context {
c.t.Helper()
startCMPServer(c.t, configFile)
c.t.Setenv("ARGOCD_BINARY_NAME", "argocd")
return c
}
// startCMPServer starts the CMP server and waits for its socket to be ready.
// It blocks until the socket file is created or times out after 10 seconds.
func startCMPServer(t *testing.T, configDir string) {
t.Helper()
pluginSockFilePath := path.Join(fixture.TmpDir, fixture.PluginSockFilePath)
t.Setenv("ARGOCD_BINARY_NAME", "argocd-cmp-server")
// ARGOCD_PLUGINSOCKFILEPATH should be set as the same value as repo server env var
t.Setenv("ARGOCD_PLUGINSOCKFILEPATH", pluginSockFilePath)
if _, err := os.Stat(pluginSockFilePath); os.IsNotExist(err) {
err := os.Mkdir(pluginSockFilePath, 0o700)
require.NoError(t, err)
}
// Read plugin config to get expected socket path
cfg, err := plugin.ReadPluginConfig(configDir)
require.NoError(t, err, "failed to read plugin config from %s", configDir)
expectedSocket := cfg.Address()
// Remove stale socket if it exists from a previous test run
if err := os.Remove(expectedSocket); err != nil && !os.IsNotExist(err) {
require.NoError(t, err, "failed to remove stale socket")
}
// Start CMP server in goroutine (non-blocking)
go func() {
errors.NewHandler(t).FailOnErr(fixture.RunWithStdin("", "", "../../dist/argocd", "--config-dir-path", configDir))
}()
// Wait for socket to be created
waitForSocket(t, expectedSocket, 10*time.Second)
}
// waitForSocket polls for a socket file to exist with exponential backoff
func waitForSocket(t *testing.T, socketPath string, timeout time.Duration) {
t.Helper()
deadline := time.Now().Add(timeout)
sleepIntervals := []time.Duration{
10 * time.Millisecond,
20 * time.Millisecond,
50 * time.Millisecond,
100 * time.Millisecond,
200 * time.Millisecond,
500 * time.Millisecond,
}
sleepIdx := 0
for time.Now().Before(deadline) {
if info, err := os.Stat(socketPath); err == nil {
if info.Mode()&os.ModeSocket != 0 {
return // Socket exists and is a socket!
}
}
if sleepIdx < len(sleepIntervals) {
time.Sleep(sleepIntervals[sleepIdx])
sleepIdx++
} else {
time.Sleep(500 * time.Millisecond)
}
}
t.Fatalf("CMP socket %s did not appear within %v", socketPath, timeout)
}

View File

@@ -0,0 +1,8 @@
# Git configuration for e2e tests
# This file ensures reproducible test behavior by disabling system credential helpers
[credential]
helper =
[core]
askPass =

View File

@@ -2,7 +2,6 @@ package e2e
import ( import (
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -255,13 +254,9 @@ func TestHydratorWithDirectory(t *testing.T) {
} }
func TestHydratorWithPlugin(t *testing.T) { func TestHydratorWithPlugin(t *testing.T) {
Given(t). ctx := Given(t)
Path("hydrator-plugin"). ctx.Path("hydrator-plugin").
And(func() { RunningCMPServer("./testdata/hydrator-plugin").
go startCMPServer(t, "./testdata/hydrator-plugin")
time.Sleep(100 * time.Millisecond)
t.Setenv("ARGOCD_BINARY_NAME", "argocd")
}).
When(). When().
CreateFromFile(func(app *Application) { CreateFromFile(func(app *Application) {
app.Spec.Source = nil app.Spec.Source = nil