2019-06-19 05:40:03 +00:00
|
|
|
package e2e
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-05-29 01:42:01 +00:00
|
|
|
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
2020-05-15 21:39:29 +00:00
|
|
|
"github.com/argoproj/gitops-engine/pkg/utils/kube"
|
2019-06-19 05:40:03 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
2021-04-01 18:44:18 +00:00
|
|
|
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
|
|
|
|
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
|
|
|
|
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app"
|
|
|
|
|
. "github.com/argoproj/argo-cd/v2/util/errors"
|
2019-06-19 05:40:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestJsonnetAppliedCorrectly(t *testing.T) {
|
|
|
|
|
Given(t).
|
|
|
|
|
Path("jsonnet-tla").
|
|
|
|
|
When().
|
|
|
|
|
Create().
|
|
|
|
|
Sync().
|
|
|
|
|
Then().
|
|
|
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
|
|
|
And(func(app *Application) {
|
2019-10-21 23:54:23 +00:00
|
|
|
manifests, err := RunCli("app", "manifests", app.Name, "--source", "live")
|
2019-06-19 05:40:03 +00:00
|
|
|
assert.NoError(t, err)
|
2020-07-20 17:11:17 +00:00
|
|
|
resources, err := kube.SplitYAML([]byte(manifests))
|
2019-06-19 05:40:03 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
index := -1
|
|
|
|
|
for i := range resources {
|
|
|
|
|
if resources[i].GetKind() == kube.DeploymentKind {
|
|
|
|
|
index = i
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.True(t, index > -1)
|
|
|
|
|
|
|
|
|
|
deployment := resources[index]
|
|
|
|
|
assert.Equal(t, "jsonnet-guestbook-ui", deployment.GetName())
|
|
|
|
|
assert.Equal(t, int64(1), *kube.GetDeploymentReplicas(deployment))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestJsonnetTlaParameterAppliedCorrectly(t *testing.T) {
|
|
|
|
|
Given(t).
|
|
|
|
|
Path("jsonnet-tla").
|
|
|
|
|
When().
|
2019-10-21 23:54:23 +00:00
|
|
|
Create("--jsonnet-tla-str", "name=testing-tla", "--jsonnet-tla-code", "replicas=0").
|
2019-06-19 05:40:03 +00:00
|
|
|
Sync().
|
|
|
|
|
Then().
|
|
|
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
|
|
|
And(func(app *Application) {
|
2019-10-21 23:54:23 +00:00
|
|
|
manifests, err := RunCli("app", "manifests", app.Name, "--source", "live")
|
2019-06-19 05:40:03 +00:00
|
|
|
assert.NoError(t, err)
|
2020-07-20 17:11:17 +00:00
|
|
|
resources, err := kube.SplitYAML([]byte(manifests))
|
2019-06-19 05:40:03 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
index := -1
|
|
|
|
|
for i := range resources {
|
|
|
|
|
if resources[i].GetKind() == kube.DeploymentKind {
|
|
|
|
|
index = i
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.True(t, index > -1)
|
|
|
|
|
|
|
|
|
|
deployment := resources[index]
|
|
|
|
|
assert.Equal(t, "testing-tla", deployment.GetName())
|
2019-10-21 23:54:23 +00:00
|
|
|
assert.Equal(t, int64(0), *kube.GetDeploymentReplicas(deployment))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestJsonnetTlaEnv(t *testing.T) {
|
|
|
|
|
Given(t).
|
|
|
|
|
Path("jsonnet-tla-cm").
|
|
|
|
|
When().
|
|
|
|
|
Create("--jsonnet-tla-str", "foo=$ARGOCD_APP_NAME", "--jsonnet-tla-code", "bar='$ARGOCD_APP_NAME'").
|
|
|
|
|
Sync().
|
|
|
|
|
Then().
|
|
|
|
|
Expect(OperationPhaseIs(OperationSucceeded)).
|
|
|
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
|
|
|
And(func(app *Application) {
|
|
|
|
|
assert.Equal(t, Name(), FailOnErr(Run(".", "kubectl", "-n", DeploymentNamespace(), "get", "cm", "my-map", "-o", "jsonpath={.data.foo}")).(string))
|
|
|
|
|
assert.Equal(t, Name(), FailOnErr(Run(".", "kubectl", "-n", DeploymentNamespace(), "get", "cm", "my-map", "-o", "jsonpath={.data.bar}")).(string))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
func TestJsonnetExtVarEnv(t *testing.T) {
|
|
|
|
|
Given(t).
|
|
|
|
|
Path("jsonnet-ext-var").
|
|
|
|
|
When().
|
|
|
|
|
Create("--jsonnet-ext-var-str", "foo=$ARGOCD_APP_NAME", "--jsonnet-ext-var-code", "bar='$ARGOCD_APP_NAME'").
|
|
|
|
|
Sync().
|
|
|
|
|
Then().
|
|
|
|
|
Expect(OperationPhaseIs(OperationSucceeded)).
|
|
|
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
|
|
|
And(func(app *Application) {
|
|
|
|
|
assert.Equal(t, Name(), FailOnErr(Run(".", "kubectl", "-n", DeploymentNamespace(), "get", "cm", "my-map", "-o", "jsonpath={.data.foo}")).(string))
|
|
|
|
|
assert.Equal(t, Name(), FailOnErr(Run(".", "kubectl", "-n", DeploymentNamespace(), "get", "cm", "my-map", "-o", "jsonpath={.data.bar}")).(string))
|
2019-06-19 05:40:03 +00:00
|
|
|
})
|
|
|
|
|
}
|
2020-04-06 22:20:07 +00:00
|
|
|
|
|
|
|
|
//Jsonnet file located in nested sub directory uses import
|
|
|
|
|
func TestJsonnetNestedDirWithImports(t *testing.T) {
|
|
|
|
|
Given(t).
|
|
|
|
|
Path("jsonnet-nested-dir-with-imports/apps").
|
|
|
|
|
When().
|
|
|
|
|
Create("--directory-recurse").
|
|
|
|
|
Sync().
|
|
|
|
|
Then().
|
|
|
|
|
Expect(OperationPhaseIs(OperationSucceeded)).
|
|
|
|
|
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
|
|
|
|
Expect(ResourceSyncStatusIs("Namespace", "hello-world", SyncStatusCodeSynced)).
|
|
|
|
|
Expect(ResourceSyncStatusIs("Namespace", "hello-root", SyncStatusCodeSynced))
|
|
|
|
|
}
|