mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
chore: enable require-error rule from errorlint linter on test folder (#18684)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@ issues:
|
||||
- SA1019
|
||||
- SA5011
|
||||
exclude-rules:
|
||||
- path: "(applicationset|cmpserver|controller|pkg|reposerver|server|test)/"
|
||||
- path: "(applicationset|cmpserver|controller|pkg|reposerver|server)/"
|
||||
text: "require-error:"
|
||||
linters:
|
||||
- testifylint
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/argoproj/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
@@ -142,7 +143,7 @@ test true login, apiKey`, output)
|
||||
defer io.Close(closer)
|
||||
|
||||
info, err := client.GetUserInfo(context.Background(), &session.GetUserInfoRequest{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", info.Username)
|
||||
}
|
||||
@@ -161,9 +162,7 @@ func TestLoginBadCredentials(t *testing.T) {
|
||||
|
||||
for _, r := range requests {
|
||||
_, err := sessionClient.Create(context.Background(), &r)
|
||||
if !assert.Error(t, err) {
|
||||
return
|
||||
}
|
||||
require.Error(t, err)
|
||||
errStatus, ok := status.FromError(err)
|
||||
if !assert.True(t, ok) {
|
||||
return
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestNamespacedGetLogsDenySwitchOn(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
_, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "permission denied")
|
||||
})
|
||||
}
|
||||
@@ -145,17 +145,17 @@ func TestNamespacedGetLogsAllowSwitchOnNS(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
@@ -203,17 +203,17 @@ func TestNamespacedGetLogsAllowSwitchOff(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", ctx.AppQualifiedName(), "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
@@ -294,7 +294,7 @@ func TestNamespacedAppCreation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, ctx.AppQualifiedName())
|
||||
}).
|
||||
When().
|
||||
@@ -342,7 +342,7 @@ func TestNamespacedAppCreationWithoutForceUpdate(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, ctx.AppQualifiedName())
|
||||
}).
|
||||
When().
|
||||
@@ -367,7 +367,7 @@ func TestNamespacedDeleteAppResource(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
if _, err := RunCli("app", "delete-resource", ctx.AppQualifiedName(), "--kind", "Service", "--resource-name", "guestbook-ui"); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
@@ -451,7 +451,7 @@ func TestNamespacedAppDeletion(t *testing.T) {
|
||||
Expect(NamespacedEvent(AppNamespace(), EventReasonResourceDeleted, "delete"))
|
||||
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, ctx.AppQualifiedName())
|
||||
}
|
||||
|
||||
@@ -590,9 +590,9 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
manifests, err := RunCli("app", "manifests", ctx.AppQualifiedName(), "--source", "live")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
resources, err := kube.SplitYAML([]byte(manifests))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
index := -1
|
||||
for i := range resources {
|
||||
@@ -606,7 +606,7 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) {
|
||||
deployment := resources[index]
|
||||
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
_, err = client.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
@@ -618,14 +618,14 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) {
|
||||
Namespace: ptr.To(deployment.GetNamespace()),
|
||||
ResourceName: ptr.To(deployment.GetName()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync))
|
||||
}
|
||||
|
||||
func TestNamespacedAppWithSecrets(t *testing.T) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
ctx := Given(t)
|
||||
@@ -685,7 +685,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", ctx.AppQualifiedName())
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, diffOutput, "username: ++++++++")
|
||||
assert.Contains(t, diffOutput, "password: ++++++++++++")
|
||||
|
||||
@@ -739,7 +739,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
// Patch deployment
|
||||
_, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Patch(context.Background(),
|
||||
"guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "test" }]`), metav1.PatchOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
When().
|
||||
Refresh(RefreshTypeNormal).
|
||||
@@ -747,7 +747,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", ctx.AppQualifiedName(), "--local-repo-root", ".", "--local", "testdata/guestbook")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, diffOutput, fmt.Sprintf("===== apps/Deployment %s/guestbook-ui ======", DeploymentNamespace()))
|
||||
}).
|
||||
Given().
|
||||
@@ -760,7 +760,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", ctx.AppQualifiedName(), "--local-repo-root", ".", "--local", "testdata/guestbook")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, diffOutput)
|
||||
}).
|
||||
Given().
|
||||
@@ -778,7 +778,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
Sync().
|
||||
And(func() {
|
||||
output, err := RunWithStdin(testdata.SSARevisionHistoryDeployment, "", "kubectl", "apply", "-n", DeploymentNamespace(), "--server-side=true", "--field-manager=revision-history-manager", "--validate=false", "--force-conflicts", "-f", "-")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "serverside-applied")
|
||||
}).
|
||||
Refresh(RefreshTypeNormal).
|
||||
@@ -805,12 +805,12 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
}]`).
|
||||
And(func() {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(3), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
And(func() {
|
||||
output, err := RunWithStdin(testdata.SSARevisionHistoryDeployment, "", "kubectl", "apply", "-n", DeploymentNamespace(), "--server-side=true", "--field-manager=revision-history-manager", "--validate=false", "--force-conflicts", "-f", "-")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "serverside-applied")
|
||||
}).
|
||||
Then().
|
||||
@@ -819,13 +819,13 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
When().Sync().Then().Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
})
|
||||
}
|
||||
@@ -897,7 +897,7 @@ func testNSEdgeCasesApplicationResources(t *testing.T, appPath string, statusCod
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", ctx.AppQualifiedName(), "--local-repo-root", ".", "--local", path.Join("testdata", appPath))
|
||||
assert.Empty(t, diffOutput)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -923,7 +923,7 @@ func TestNamespacedResourceAction(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
@@ -935,7 +935,7 @@ func TestNamespacedResourceAction(t *testing.T) {
|
||||
Namespace: ptr.To(DeploymentNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
@@ -948,10 +948,10 @@ func TestNamespacedResourceAction(t *testing.T) {
|
||||
Action: ptr.To("sample"),
|
||||
AppNamespace: ptr.To(AppNamespace()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", deployment.Labels["sample"])
|
||||
})
|
||||
@@ -973,7 +973,7 @@ func TestNamespacedSyncResourceByLabel(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "sync", ctx.AppQualifiedName(), "--label", "this-label=does-not-exist")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "level=fatal")
|
||||
})
|
||||
}
|
||||
@@ -1042,10 +1042,10 @@ func TestNamespacedNoLocalSyncWithAutosyncEnabled(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "set", app.QualifiedName(), "--sync-policy", "automated")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = RunCli("app", "sync", app.QualifiedName(), "--local", guestbookPathLocal)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "Cannot use local sync")
|
||||
})
|
||||
}
|
||||
@@ -1061,11 +1061,11 @@ func TestNamespacedLocalSyncDryRunWithASEnabled(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "set", app.QualifiedName(), "--sync-policy", "automated")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
appBefore := app.DeepCopy()
|
||||
_, err = RunCli("app", "sync", app.QualifiedName(), "--dry-run", "--local-repo-root", ".", "--local", guestbookPathLocal)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
appAfter := app.DeepCopy()
|
||||
assert.True(t, reflect.DeepEqual(appBefore, appAfter))
|
||||
@@ -1091,8 +1091,9 @@ func TestNamespacedSyncAsync(t *testing.T) {
|
||||
func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
||||
assertError := func(err error, message string) {
|
||||
if successful {
|
||||
assert.NoError(t, err)
|
||||
} else if assert.Error(t, err) {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), message)
|
||||
}
|
||||
}
|
||||
@@ -1501,7 +1502,7 @@ func TestNamespacedOrphanedResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1517,7 +1518,7 @@ func TestNamespacedOrphanedResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1534,7 +1535,7 @@ func TestNamespacedOrphanedResource(t *testing.T) {
|
||||
Expect(NoConditions()).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1551,7 +1552,7 @@ func TestNamespacedOrphanedResource(t *testing.T) {
|
||||
Expect(NoConditions()).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1676,7 +1677,7 @@ func TestNamespacedSyncWithInfos(t *testing.T) {
|
||||
_, err := RunCli("app", "sync", app.QualifiedName(),
|
||||
"--info", fmt.Sprintf("%s=%s", expectedInfo[0].Name, expectedInfo[0].Value),
|
||||
"--info", fmt.Sprintf("%s=%s", expectedInfo[1].Name, expectedInfo[1].Value))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
@@ -1700,7 +1701,7 @@ func TestNamespacedCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
app, err := AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, app.Status.Conditions)
|
||||
})
|
||||
}
|
||||
@@ -1787,19 +1788,19 @@ func TestNamespacedListResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
assert.Contains(t, output, "guestbook-ui")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName(), "--orphaned=true")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
assert.NotContains(t, output, "guestbook-ui")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.QualifiedName(), "--orphaned=false")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
assert.Contains(t, output, "guestbook-ui")
|
||||
}).
|
||||
@@ -1831,7 +1832,7 @@ func TestNamespacedNamespaceAutoCreation(t *testing.T) {
|
||||
defer func() {
|
||||
if !t.Skipped() {
|
||||
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
Given(t).
|
||||
@@ -1859,7 +1860,7 @@ func TestNamespacedNamespaceAutoCreation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
// Verify delete app does not delete the namespace auto created
|
||||
output, err := Run("", "kubectl", "get", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, updatedNamespace)
|
||||
})
|
||||
}
|
||||
@@ -1875,7 +1876,7 @@ func TestNamespacedNamespaceAutoCreationWithMetadata(t *testing.T) {
|
||||
defer func() {
|
||||
if !t.Skipped() {
|
||||
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
ctx := Given(t)
|
||||
@@ -1968,7 +1969,7 @@ func TestNamespacedNamespaceAutoCreationWithMetadataAndNsManifest(t *testing.T)
|
||||
defer func() {
|
||||
if !t.Skipped() {
|
||||
_, err := Run("", "kubectl", "delete", "namespace", namespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -2022,7 +2023,7 @@ func TestNamespacedNamespaceAutoCreationWithPreexistingNs(t *testing.T) {
|
||||
defer func() {
|
||||
if !t.Skipped() {
|
||||
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -2044,7 +2045,7 @@ metadata:
|
||||
errors.CheckError(err)
|
||||
|
||||
_, err = Run("", "kubectl", "apply", "-f", tmpFile.Name())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := Given(t)
|
||||
ctx.
|
||||
@@ -2161,7 +2162,7 @@ func TestNamespacedCreateDisableValidation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "create", app.QualifiedName(), "--upsert", "--validate=false", "--repo", RepoURL(RepoURLTypeFile),
|
||||
"--path", "baddir2", "--project", app.Spec.Project, "--dest-server", KubernetesInternalAPIServerAddr, "--dest-namespace", DeploymentNamespace())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
When().
|
||||
AppSet("--path", "baddir3", "--validate=false")
|
||||
@@ -2252,38 +2253,38 @@ definitions:
|
||||
// tests resource actions on a CRD using status subresource
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "StatusSubResource", "update-both")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text := FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "StatusSubResource", "update-spec")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-spec", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "StatusSubResource", "update-status")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-status", text)
|
||||
}).
|
||||
// tests resource actions on a CRD *not* using status subresource
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "NonStatusSubResource", "update-both")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text := FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "NonStatusSubResource", "update-spec")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-spec", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.QualifiedName(), "--kind", "NonStatusSubResource", "update-status")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-status", text)
|
||||
})
|
||||
@@ -2302,17 +2303,17 @@ func TestNamespacedAppLogs(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", app.QualifiedName(), "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", app.QualifiedName(), "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(5, "app", "logs", app.QualifiedName(), "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestGetLogsDenySwitchOn(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
_, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "permission denied")
|
||||
})
|
||||
}
|
||||
@@ -151,17 +151,17 @@ func TestGetLogsAllowSwitchOn(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
@@ -207,17 +207,17 @@ func TestGetLogsAllowSwitchOff(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
@@ -401,7 +401,7 @@ func TestAppCreation(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, Name())
|
||||
}).
|
||||
When().
|
||||
@@ -446,7 +446,7 @@ func TestAppCreationWithoutForceUpdate(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, Name())
|
||||
}).
|
||||
When().
|
||||
@@ -508,7 +508,7 @@ func TestDeleteAppResource(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
if _, err := RunCli("app", "delete-resource", Name(), "--kind", "Service", "--resource-name", "guestbook-ui"); err != nil {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
@@ -602,7 +602,7 @@ func TestAppDeletion(t *testing.T) {
|
||||
Expect(Event(EventReasonResourceDeleted, "delete"))
|
||||
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, Name())
|
||||
}
|
||||
|
||||
@@ -726,9 +726,9 @@ func TestManipulateApplicationResources(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
manifests, err := RunCli("app", "manifests", app.Name, "--source", "live")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
resources, err := kube.SplitYAML([]byte(manifests))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
index := -1
|
||||
for i := range resources {
|
||||
@@ -742,7 +742,7 @@ func TestManipulateApplicationResources(t *testing.T) {
|
||||
deployment := resources[index]
|
||||
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
_, err = client.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
@@ -753,21 +753,21 @@ func TestManipulateApplicationResources(t *testing.T) {
|
||||
Namespace: ptr.To(deployment.GetNamespace()),
|
||||
ResourceName: ptr.To(deployment.GetName()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync))
|
||||
}
|
||||
|
||||
func assetSecretDataHidden(t *testing.T, manifest string) {
|
||||
secret, err := UnmarshalToUnstructured(manifest)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, hasStringData, err := unstructured.NestedMap(secret.Object, "stringData")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, hasStringData)
|
||||
|
||||
secretData, hasData, err := unstructured.NestedMap(secret.Object, "data")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, hasData)
|
||||
for _, v := range secretData {
|
||||
assert.Regexp(t, regexp.MustCompile(`[*]*`), v)
|
||||
@@ -784,7 +784,7 @@ func assetSecretDataHidden(t *testing.T, manifest string) {
|
||||
|
||||
func TestAppWithSecrets(t *testing.T) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
Given(t).
|
||||
@@ -837,7 +837,7 @@ func TestAppWithSecrets(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, diffOutput, "username: ++++++++")
|
||||
assert.Contains(t, diffOutput, "password: ++++++++++++")
|
||||
|
||||
@@ -888,7 +888,7 @@ func TestResourceDiffing(t *testing.T) {
|
||||
// Patch deployment
|
||||
_, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Patch(context.Background(),
|
||||
"guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "test" }]`), metav1.PatchOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
When().
|
||||
Refresh(RefreshTypeNormal).
|
||||
@@ -896,7 +896,7 @@ func TestResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name, "--local", "testdata", "--server-side-generate")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, diffOutput, fmt.Sprintf("===== apps/Deployment %s/guestbook-ui ======", DeploymentNamespace()))
|
||||
}).
|
||||
Given().
|
||||
@@ -909,7 +909,7 @@ func TestResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name, "--local", "testdata", "--server-side-generate")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, diffOutput)
|
||||
}).
|
||||
Given().
|
||||
@@ -927,7 +927,7 @@ func TestResourceDiffing(t *testing.T) {
|
||||
Sync().
|
||||
And(func() {
|
||||
output, err := RunWithStdin(testdata.SSARevisionHistoryDeployment, "", "kubectl", "apply", "-n", DeploymentNamespace(), "--server-side=true", "--field-manager=revision-history-manager", "--validate=false", "--force-conflicts", "-f", "-")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "serverside-applied")
|
||||
}).
|
||||
Refresh(RefreshTypeNormal).
|
||||
@@ -954,12 +954,12 @@ func TestResourceDiffing(t *testing.T) {
|
||||
}]`).
|
||||
And(func() {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(3), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
And(func() {
|
||||
output, err := RunWithStdin(testdata.SSARevisionHistoryDeployment, "", "kubectl", "apply", "-n", DeploymentNamespace(), "--server-side=true", "--field-manager=revision-history-manager", "--validate=false", "--force-conflicts", "-f", "-")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "serverside-applied")
|
||||
}).
|
||||
Then().
|
||||
@@ -968,13 +968,13 @@ func TestResourceDiffing(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
When().Sync().Then().Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
})
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ func testEdgeCasesApplicationResources(t *testing.T, appPath string, statusCode
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name, "--local", "testdata", "--server-side-generate")
|
||||
assert.Empty(t, diffOutput)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1060,7 +1060,7 @@ func TestOldStyleResourceAction(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
@@ -1071,7 +1071,7 @@ func TestOldStyleResourceAction(t *testing.T) {
|
||||
Namespace: ptr.To(DeploymentNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
@@ -1083,10 +1083,10 @@ func TestOldStyleResourceAction(t *testing.T) {
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
Action: ptr.To("sample"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
deployment, err := KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", deployment.Labels["sample"])
|
||||
})
|
||||
@@ -1166,7 +1166,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
@@ -1177,7 +1177,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
||||
Namespace: ptr.To(DeploymentNamespace()),
|
||||
ResourceName: ptr.To("hello"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
@@ -1189,10 +1189,10 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
||||
ResourceName: ptr.To("hello"),
|
||||
Action: ptr.To("sample"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = KubeClientset.BatchV1().Jobs(DeploymentNamespace()).Get(context.Background(), "hello-123", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1277,7 +1277,7 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
closer, client, err := ArgoCDClientset.NewApplicationClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
@@ -1288,7 +1288,7 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
||||
Namespace: ptr.To(DeploymentNamespace()),
|
||||
ResourceName: ptr.To("hello"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
@@ -1300,15 +1300,15 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
||||
ResourceName: ptr.To("hello"),
|
||||
Action: ptr.To("sample"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert new Job was created
|
||||
_, err = KubeClientset.BatchV1().Jobs(DeploymentNamespace()).Get(context.Background(), "hello-123", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
// Assert the original CronJob was patched
|
||||
cronJob, err := KubeClientset.BatchV1().CronJobs(DeploymentNamespace()).Get(context.Background(), "hello", metav1.GetOptions{})
|
||||
assert.Equal(t, "aValue", cronJob.Labels["aKey"])
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1325,7 +1325,7 @@ func TestSyncResourceByLabel(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "sync", app.Name, "--label", "this-label=does-not-exist")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "level=fatal")
|
||||
})
|
||||
}
|
||||
@@ -1343,7 +1343,7 @@ func TestSyncResourceByProject(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "sync", app.Name, "--project", "this-project-does-not-exist")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "level=fatal")
|
||||
})
|
||||
}
|
||||
@@ -1405,10 +1405,10 @@ func TestNoLocalSyncWithAutosyncEnabled(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "set", app.Name, "--sync-policy", "automated")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = RunCli("app", "sync", app.Name, "--local", guestbookPathLocal)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1421,11 +1421,11 @@ func TestLocalSyncDryRunWithAutosyncEnabled(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "set", app.Name, "--sync-policy", "automated")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
appBefore := app.DeepCopy()
|
||||
_, err = RunCli("app", "sync", app.Name, "--dry-run", "--local-repo-root", ".", "--local", guestbookPathLocal)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
appAfter := app.DeepCopy()
|
||||
assert.True(t, reflect.DeepEqual(appBefore, appAfter))
|
||||
@@ -1449,8 +1449,9 @@ func TestSyncAsync(t *testing.T) {
|
||||
func assertResourceActions(t *testing.T, appName string, successful bool) {
|
||||
assertError := func(err error, message string) {
|
||||
if successful {
|
||||
assert.NoError(t, err)
|
||||
} else if assert.Error(t, err) {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), message)
|
||||
}
|
||||
}
|
||||
@@ -1921,7 +1922,7 @@ func TestOrphanedResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1936,7 +1937,7 @@ func TestOrphanedResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1952,7 +1953,7 @@ func TestOrphanedResource(t *testing.T) {
|
||||
Expect(NoConditions()).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -1968,7 +1969,7 @@ func TestOrphanedResource(t *testing.T) {
|
||||
Expect(NoConditions()).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
}).
|
||||
Given().
|
||||
@@ -2089,7 +2090,7 @@ func TestSyncWithInfos(t *testing.T) {
|
||||
_, err := RunCli("app", "sync", app.Name,
|
||||
"--info", fmt.Sprintf("%s=%s", expectedInfo[0].Name, expectedInfo[0].Value),
|
||||
"--info", fmt.Sprintf("%s=%s", expectedInfo[1].Name, expectedInfo[1].Value))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
@@ -2111,7 +2112,7 @@ func TestCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
app, err := AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, app.Status.Conditions)
|
||||
})
|
||||
}
|
||||
@@ -2191,19 +2192,19 @@ func TestListResource(t *testing.T) {
|
||||
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
assert.Contains(t, output, "guestbook-ui")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name, "--orphaned=true")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "orphaned-configmap")
|
||||
assert.NotContains(t, output, "guestbook-ui")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := RunCli("app", "resources", app.Name, "--orphaned=false")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, output, "orphaned-configmap")
|
||||
assert.Contains(t, output, "guestbook-ui")
|
||||
}).
|
||||
@@ -2234,7 +2235,7 @@ func TestNamespaceAutoCreation(t *testing.T) {
|
||||
defer func() {
|
||||
if !t.Skipped() {
|
||||
_, err := Run("", "kubectl", "delete", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
Given(t).
|
||||
@@ -2246,7 +2247,7 @@ func TestNamespaceAutoCreation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
// Make sure the namespace we are about to update to does not exist
|
||||
_, err := Run("", "kubectl", "get", "namespace", updatedNamespace)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "not found")
|
||||
}).
|
||||
When().
|
||||
@@ -2265,7 +2266,7 @@ func TestNamespaceAutoCreation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
// Verify delete app does not delete the namespace auto created
|
||||
output, err := Run("", "kubectl", "get", "namespace", updatedNamespace)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, updatedNamespace)
|
||||
})
|
||||
}
|
||||
@@ -2294,7 +2295,7 @@ func TestCreateDisableValidation(t *testing.T) {
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "create", app.Name, "--upsert", "--validate=false", "--repo", RepoURL(RepoURLTypeFile),
|
||||
"--path", "baddir2", "--project", app.Spec.Project, "--dest-server", KubernetesInternalAPIServerAddr, "--dest-namespace", DeploymentNamespace())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
When().
|
||||
AppSet("--path", "baddir3", "--validate=false")
|
||||
@@ -2381,38 +2382,38 @@ definitions:
|
||||
// tests resource actions on a CRD using status subresource
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "actions", "run", app.Name, "--kind", "StatusSubResource", "update-both")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text := FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.Name, "--kind", "StatusSubResource", "update-spec")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-spec", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.Name, "--kind", "StatusSubResource", "update-status")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "statussubresources", "status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-status", text)
|
||||
}).
|
||||
// tests resource actions on a CRD *not* using status subresource
|
||||
And(func(app *Application) {
|
||||
_, err := RunCli("app", "actions", "run", app.Name, "--kind", "NonStatusSubResource", "update-both")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text := FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-both", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.Name, "--kind", "NonStatusSubResource", "update-spec")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.spec.foo}")).(string)
|
||||
assert.Equal(t, "update-spec", text)
|
||||
|
||||
_, err = RunCli("app", "actions", "run", app.Name, "--kind", "NonStatusSubResource", "update-status")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
text = FailOnErr(Run(".", "kubectl", "-n", app.Spec.Destination.Namespace, "get", "nonstatussubresources", "non-status-subresource", "-o", "jsonpath={.status.bar}")).(string)
|
||||
assert.Equal(t, "update-status", text)
|
||||
})
|
||||
@@ -2429,17 +2430,17 @@ func TestAppLogs(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Deployment", "--group", "", "--name", "guestbook-ui")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Pod")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "Hi")
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
out, err := RunCliWithRetry(appLogsRetryCount, "app", "logs", app.Name, "--kind", "Service")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, out, "Hi")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
@@ -39,7 +40,7 @@ func TestMultiSourceAppCreation(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, Name())
|
||||
}).
|
||||
Expect(Success("")).
|
||||
@@ -94,7 +95,7 @@ func TestMultiSourceAppWithHelmExternalValueFiles(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, Name())
|
||||
}).
|
||||
Expect(Success("")).
|
||||
@@ -142,7 +143,7 @@ func TestMultiSourceAppWithSourceOverride(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, Name())
|
||||
}).
|
||||
Expect(Success("")).
|
||||
@@ -162,7 +163,7 @@ func TestMultiSourceAppWithSourceOverride(t *testing.T) {
|
||||
|
||||
// check if label was added to the pod to make sure resource was taken from the later source
|
||||
output, err := Run("", "kubectl", "describe", "pods", "pod-1", "-n", DeploymentNamespace())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "foo=bar")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
|
||||
@@ -37,7 +38,7 @@ func TestAppCreationInOtherNamespace(t *testing.T) {
|
||||
And(func(_ *Application) {
|
||||
// app should be listed
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, ctx.AppName())
|
||||
}).
|
||||
When().
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets"
|
||||
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
|
||||
@@ -2612,7 +2613,7 @@ func TestSCMProviderGeneratorSCMProviderNotAllowed(t *testing.T) {
|
||||
And(func() {
|
||||
// app should be listed
|
||||
output, err := fixture.RunCli("appset", "get", "scm-provider-generator-scm-provider-not-allowed")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "scm provider not allowed")
|
||||
})
|
||||
}
|
||||
@@ -3024,7 +3025,7 @@ func TestPullRequestGeneratorNotAllowedSCMProvider(t *testing.T) {
|
||||
And(func() {
|
||||
// app should be listed
|
||||
output, err := fixture.RunCli("appset", "get", "pull-request-generator-not-allowed-scm")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, "scm provider not allowed")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
@@ -19,7 +20,7 @@ func TestCliAppCommand(t *testing.T) {
|
||||
CreateApp().
|
||||
And(func() {
|
||||
output, err := RunCli("app", "sync", Name(), "--timeout", "90")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
vars := map[string]interface{}{"Name": Name(), "Namespace": DeploymentNamespace()}
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(`Pod {{.Namespace}} pod Synced Progressing pod/pod created`, vars))
|
||||
assert.Contains(t, NormalizeOutput(output), Tmpl(`Pod {{.Namespace}} hook Succeeded Sync pod/hook created`, vars))
|
||||
@@ -29,7 +30,7 @@ func TestCliAppCommand(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(_ *Application) {
|
||||
output, err := RunCli("app", "list")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
expected := Tmpl(
|
||||
`{{.Name}} https://kubernetes.default.svc {{.Namespace}} default Synced Healthy Manual <none>`,
|
||||
map[string]interface{}{"Name": Name(), "Namespace": DeploymentNamespace()})
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
@@ -25,7 +26,7 @@ func TestClusterRoleBinding(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name, "--revision=HEAD")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, diffOutput)
|
||||
}).
|
||||
When().
|
||||
@@ -37,7 +38,7 @@ func TestClusterRoleBinding(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
diffOutput, err := RunCli("app", "diff", app.Name, "--revision=HEAD")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, diffOutput)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -67,12 +67,12 @@ func TestCustomToolWithGitCredsTemplate(t *testing.T) {
|
||||
Expect(HealthIs(health.HealthStatusHealthy)).
|
||||
And(func(app *Application) {
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.GitUsername}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.GitPassword}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
}
|
||||
@@ -107,18 +107,18 @@ func TestCustomToolWithEnv(t *testing.T) {
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.Bar}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "baz", output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.Foo}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "bar", output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
expectedKubeVersion := GetVersions().ServerVersion.Format("%s.%s")
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.KubeVersion}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedKubeVersion, output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
@@ -127,7 +127,7 @@ func TestCustomToolWithEnv(t *testing.T) {
|
||||
sort.Strings(expectedApiVersionSlice)
|
||||
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.KubeApiVersion}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
outputSlice := strings.Split(output, ",")
|
||||
sort.Strings(outputSlice)
|
||||
|
||||
@@ -261,13 +261,13 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) {
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.Bar}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "baz", output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
expectedKubeVersion := GetVersions().ServerVersion.Format("%s.%s")
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.KubeVersion}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedKubeVersion, output)
|
||||
}).
|
||||
And(func(app *Application) {
|
||||
@@ -276,7 +276,7 @@ func TestCMPDiscoverWithFindCommandWithEnv(t *testing.T) {
|
||||
sort.Strings(expectedApiVersionSlice)
|
||||
|
||||
output, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "cm", ctx.AppName(), "-o", "jsonpath={.metadata.annotations.KubeApiVersion}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
outputSlice := strings.Split(output, ",")
|
||||
sort.Strings(outputSlice)
|
||||
|
||||
@@ -303,7 +303,7 @@ func TestPruneResourceFromCMP(t *testing.T) {
|
||||
Expect(DoesNotExist()).
|
||||
AndAction(func() {
|
||||
_, err := Run("", "kubectl", "-n", DeploymentNamespace(), "get", "deployment", "guestbook-ui")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -65,7 +66,7 @@ func TestDeploymentWithAnnotationTrackingMode(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
out, err := RunCli("app", "manifests", ctx.AppName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, fmt.Sprintf(`annotations:
|
||||
argocd.argoproj.io/tracking-id: %s:apps/Deployment:%s/nginx-deployment
|
||||
`, ctx.AppName(), DeploymentNamespace()))
|
||||
@@ -88,7 +89,7 @@ func TestDeploymentWithLabelTrackingMode(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
out, err := RunCli("app", "manifests", ctx.AppName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, fmt.Sprintf(`labels:
|
||||
app: nginx
|
||||
app.kubernetes.io/instance: %s
|
||||
@@ -111,7 +112,7 @@ func TestDeploymentWithoutTrackingMode(t *testing.T) {
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
out, err := RunCli("app", "manifests", ctx.AppName())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, fmt.Sprintf(`labels:
|
||||
app: nginx
|
||||
app.kubernetes.io/instance: %s
|
||||
@@ -265,12 +266,12 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
},
|
||||
}
|
||||
_, err := KubeClientset.CoreV1().Namespaces().Create(context.Background(), &ns, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a ServiceAccount in that Namespace, which will be used for the Argo CD Cluster SEcret
|
||||
serviceAccountName := username + "-serviceaccount"
|
||||
err = clusterauth.CreateServiceAccount(KubeClientset, serviceAccountName, ns.Name)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a Role that allows the ServiceAccount to read/write all within the Namespace
|
||||
role := rbacv1.Role{
|
||||
@@ -285,7 +286,7 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
}},
|
||||
}
|
||||
_, err = KubeClientset.RbacV1().Roles(role.Namespace).Create(context.Background(), &role, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Bind the Role with the ServiceAccount in the Namespace
|
||||
roleBinding := rbacv1.RoleBinding{
|
||||
@@ -305,11 +306,11 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
},
|
||||
}
|
||||
_, err = KubeClientset.RbacV1().RoleBindings(roleBinding.Namespace).Create(context.Background(), &roleBinding, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Retrieve the bearer token from the ServiceAccount
|
||||
token, err := clusterauth.GetServiceAccountBearerToken(KubeClientset, ns.Name, serviceAccountName, time.Second*60)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, token)
|
||||
|
||||
// In order to test a cluster-scoped Argo CD Cluster Secret, we may optionally grant the ServiceAccount read-all permissions at cluster scope.
|
||||
@@ -317,10 +318,10 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
clusterRole, clusterRoleBinding := generateReadOnlyClusterRoleandBindingForServiceAccount(username, username)
|
||||
|
||||
_, err := KubeClientset.RbacV1().ClusterRoles().Create(context.Background(), &clusterRole, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = KubeClientset.RbacV1().ClusterRoleBindings().Create(context.Background(), &clusterRoleBinding, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// Build the Argo CD Cluster Secret by using the service account token, and extracting needed values from kube config
|
||||
@@ -332,10 +333,10 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
}
|
||||
|
||||
jsonStringBytes, err := json.Marshal(clusterSecretConfigJSON)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, apiURL, err := extractKubeConfigValues()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
clusterResourcesField := ""
|
||||
namespacesField := ""
|
||||
@@ -353,7 +354,7 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
||||
|
||||
// Finally, create the Cluster secret in the Argo CD E2E namespace
|
||||
_, err = KubeClientset.CoreV1().Secrets(secret.Namespace).Create(context.Background(), &secret, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// extractKubeConfigValues returns contents of the local environment's kubeconfig, using standard path resolution mechanism.
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -76,7 +77,7 @@ func TestHookDiff(t *testing.T) {
|
||||
Then().
|
||||
And(func(_ *Application) {
|
||||
output, err := RunCli("app", "diff", Name())
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, output, "name: pod")
|
||||
assert.NotContains(t, output, "name: hook")
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/argoproj/gitops-engine/pkg/utils/kube"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
@@ -23,9 +24,9 @@ func TestJsonnetAppliedCorrectly(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
manifests, err := RunCli("app", "manifests", app.Name, "--source", "live")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
resources, err := kube.SplitYAML([]byte(manifests))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
index := -1
|
||||
for i := range resources {
|
||||
@@ -53,9 +54,9 @@ func TestJsonnetTlaParameterAppliedCorrectly(t *testing.T) {
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
manifests, err := RunCli("app", "manifests", app.Name, "--source", "live")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
resources, err := kube.SplitYAML([]byte(manifests))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
index := -1
|
||||
for i := range resources {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/argoproj/gitops-engine/pkg/health"
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
@@ -22,7 +23,7 @@ func TestKustomize2AppSource(t *testing.T) {
|
||||
"", "kubectl", "-n="+fixture.DeploymentNamespace(),
|
||||
"get", kind, name,
|
||||
"-ojsonpath={.metadata.labels.patched-by}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "argo-cd", labelValue, "wrong value of 'patched-by' label of %s %s", kind, name)
|
||||
}
|
||||
}
|
||||
@@ -189,7 +190,7 @@ func TestKustomizeReplicas2AppSource(t *testing.T) {
|
||||
"", "kubectl", "-n="+fixture.DeploymentNamespace(),
|
||||
"get", kind, name,
|
||||
"-ojsonpath={.spec.replicas}")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, strconv.Itoa(deploymentReplicas), replicas, "wrong value of replicas %s %s", kind, name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/argoproj/argo-cd/v2/pkg/apiclient/notification"
|
||||
@@ -15,7 +16,7 @@ func TestNotificationsListServices(t *testing.T) {
|
||||
ctx.When().
|
||||
SetParamInNotificationConfigMap("service.webhook.test", "url: https://test.example.com").
|
||||
Then().Services(func(services *notification.ServiceList, err error) {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*notification.Service{{Name: ptr.To("test")}}, services.Items)
|
||||
})
|
||||
}
|
||||
@@ -25,7 +26,7 @@ func TestNotificationsListTemplates(t *testing.T) {
|
||||
ctx.When().
|
||||
SetParamInNotificationConfigMap("template.app-created", "email:\n subject: Application {{.app.metadata.name}} has been created.\nmessage: Application {{.app.metadata.name}} has been created.\nteams:\n title: Application {{.app.metadata.name}} has been created.\n").
|
||||
Then().Templates(func(templates *notification.TemplateList, err error) {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*notification.Template{{Name: ptr.To("app-created")}}, templates.Items)
|
||||
})
|
||||
}
|
||||
@@ -35,7 +36,7 @@ func TestNotificationsListTriggers(t *testing.T) {
|
||||
ctx.When().
|
||||
SetParamInNotificationConfigMap("trigger.on-created", "- description: Application is created.\n oncePer: app.metadata.name\n send:\n - app-created\n when: \"true\"\n").
|
||||
Then().Triggers(func(triggers *notification.TriggerList, err error) {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*notification.Trigger{{Name: ptr.To("on-created")}}, triggers.Items)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
@@ -28,7 +29,7 @@ func assertProjHasEvent(t *testing.T, a *v1alpha1.AppProject, message string, re
|
||||
"involvedObject.namespace": fixture.TestNamespace(),
|
||||
}).String(),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := range list.Items {
|
||||
event := list.Items[i]
|
||||
@@ -49,10 +50,10 @@ func TestProjectCreation(t *testing.T) {
|
||||
"-d", "https://192.168.99.100:8443,service",
|
||||
"-s", "https://github.com/argoproj/argo-cd.git",
|
||||
"--orphaned-resources")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 2)
|
||||
|
||||
@@ -76,19 +77,19 @@ func TestProjectCreation(t *testing.T) {
|
||||
proj.ResourceVersion = ""
|
||||
data, err := json.Marshal(proj)
|
||||
stdinString := string(data)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// fail without upsert flag
|
||||
_, err = fixture.RunCliWithStdin(stdinString, "proj", "create",
|
||||
"-f", "-")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
|
||||
// succeed with the upsert flag
|
||||
_, err = fixture.RunCliWithStdin(stdinString, "proj", "create",
|
||||
"-f", "-", "--upsert")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
proj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newDescription, proj.Spec.Description)
|
||||
}
|
||||
|
||||
@@ -98,10 +99,10 @@ func TestProjectDeletion(t *testing.T) {
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "delete", projectName)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.True(t, errors.IsNotFound(err))
|
||||
@@ -114,17 +115,17 @@ func TestSetProject(t *testing.T) {
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "set", projectName,
|
||||
"--description", "updated description",
|
||||
"-d", "https://192.168.99.100:8443,default",
|
||||
"-d", "https://192.168.99.100:8443,service",
|
||||
"--orphaned-resources-warn=false")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 2)
|
||||
|
||||
@@ -162,25 +163,25 @@ func TestAddProjectDestination(t *testing.T) {
|
||||
"https://192.168.99.100:8443",
|
||||
"test1",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "already defined"))
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-destination", projectName,
|
||||
"!*",
|
||||
"test1",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "server has an invalid format, '!*'"))
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-destination", projectName,
|
||||
"https://192.168.99.100:8443",
|
||||
"!*",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "namespace has an invalid format, '!*'"))
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 1)
|
||||
|
||||
@@ -209,7 +210,7 @@ func TestAddProjectDestinationWithName(t *testing.T) {
|
||||
}
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 1)
|
||||
|
||||
@@ -248,7 +249,7 @@ func TestRemoveProjectDestination(t *testing.T) {
|
||||
"https://192.168.99.100:8443",
|
||||
"test1",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "does not exist")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
@@ -276,10 +277,10 @@ func TestAddProjectSource(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.SourceRepos, 1)
|
||||
|
||||
@@ -297,17 +298,17 @@ func TestRemoveProjectSource(t *testing.T) {
|
||||
},
|
||||
}, metav1.CreateOptions{})
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "remove-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "remove-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Empty(t, proj.Spec.SourceRepos)
|
||||
assertProjHasEvent(t, proj, "update", argo.EventReasonResourceUpdated)
|
||||
@@ -346,48 +347,48 @@ func TestUseJWTToken(t *testing.T) {
|
||||
SourceRepos: []string{"*"},
|
||||
},
|
||||
}, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Create(context.Background(), testApp, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "role", "create", projectName, roleName)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
roleGetResult, err := fixture.RunCli("proj", "role", "get", projectName, roleName)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, strings.HasSuffix(roleGetResult, "ID ISSUED-AT EXPIRES-AT"))
|
||||
|
||||
_, err = fixture.RunCli("proj", "role", "create-token", projectName, roleName)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create second role with kubectl, to test that it will not affect 1st role
|
||||
_, err = fixture.Run("", "kubectl", "patch", "appproject", projectName, "--type", "merge",
|
||||
"-n", fixture.TestNamespace(),
|
||||
"-p", fmt.Sprintf(`{"spec":{"roles":[{"name":"%s"},{"name":"%s"}]}}`, roleName, roleName2))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "role", "create-token", projectName, roleName2)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, action := range []string{"get", "update", "sync", "create", "override", "*"} {
|
||||
_, err = fixture.RunCli("proj", "role", "add-policy", projectName, roleName, "-a", action, "-o", "*", "-p", "allow")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
newProj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, newProj.Status.JWTTokensByRole[roleName].Items, 1)
|
||||
assert.ElementsMatch(t, newProj.Status.JWTTokensByRole[roleName].Items, newProj.Spec.Roles[0].JWTTokens)
|
||||
|
||||
roleGetResult, err = fixture.RunCli("proj", "role", "get", projectName, roleName)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, strings.Contains(roleGetResult, strconv.FormatInt(newProj.Status.JWTTokensByRole[roleName].Items[0].IssuedAt, 10)))
|
||||
|
||||
_, err = fixture.RunCli("proj", "role", "delete-token", projectName, roleName, strconv.FormatInt(newProj.Status.JWTTokensByRole[roleName].Items[0].IssuedAt, 10))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
newProj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, newProj.Status.JWTTokensByRole[roleName].Items)
|
||||
assert.Nil(t, newProj.Spec.Roles[0].JWTTokens)
|
||||
}
|
||||
@@ -418,11 +419,11 @@ func TestAddOrphanedIgnore(t *testing.T) {
|
||||
"--name",
|
||||
"name",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "already defined"))
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.OrphanedResources.Ignore, 1)
|
||||
|
||||
@@ -465,7 +466,7 @@ func TestRemoveOrphanedIgnore(t *testing.T) {
|
||||
"--name",
|
||||
"name",
|
||||
)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "does not exist")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
@@ -546,7 +547,7 @@ func createAndConfigGlobalProject() error {
|
||||
func TestGetVirtualProjectNoMatch(t *testing.T) {
|
||||
fixture.EnsureCleanState(t)
|
||||
err := createAndConfigGlobalProject()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create project which does not match global project settings
|
||||
projectName := "proj-" + fixture.Name()
|
||||
@@ -555,15 +556,15 @@ func TestGetVirtualProjectNoMatch(t *testing.T) {
|
||||
"-d", fmt.Sprintf("%s,*", v1alpha1.KubernetesInternalAPIServerAddr),
|
||||
"-s", "*",
|
||||
"--orphaned-resources")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an app belongs to proj project
|
||||
_, err = fixture.RunCli("app", "create", fixture.Name(), "--repo", fixture.RepoURL(fixture.RepoURLTypeFile),
|
||||
"--path", guestbookPath, "--project", proj.Name, "--dest-server", v1alpha1.KubernetesInternalAPIServerAddr, "--dest-namespace", fixture.DeploymentNamespace())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Waiting for the app to be successfully created.
|
||||
// Else the sync would fail to retrieve the app resources.
|
||||
@@ -571,17 +572,17 @@ func TestGetVirtualProjectNoMatch(t *testing.T) {
|
||||
|
||||
// App trying to sync a resource which is not blacked listed anywhere
|
||||
_, err = fixture.RunCli("app", "sync", fixture.Name(), "--resource", "apps:Deployment:guestbook-ui", "--timeout", fmt.Sprintf("%v", 10))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// app trying to sync a resource which is black listed by global project
|
||||
_, err = fixture.RunCli("app", "sync", fixture.Name(), "--resource", ":Service:guestbook-ui", "--timeout", fmt.Sprintf("%v", 10))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGetVirtualProjectMatch(t *testing.T) {
|
||||
fixture.EnsureCleanState(t)
|
||||
err := createAndConfigGlobalProject()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create project which matches global project settings
|
||||
projectName := "proj-" + fixture.Name()
|
||||
@@ -590,20 +591,20 @@ func TestGetVirtualProjectMatch(t *testing.T) {
|
||||
"-d", fmt.Sprintf("%s,*", v1alpha1.KubernetesInternalAPIServerAddr),
|
||||
"-s", "*",
|
||||
"--orphaned-resources")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add a label to this project so that this project match global project selector
|
||||
proj.Labels = map[string]string{"opt": "me"}
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(context.Background(), proj, metav1.UpdateOptions{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an app belongs to proj project
|
||||
_, err = fixture.RunCli("app", "create", fixture.Name(), "--repo", fixture.RepoURL(fixture.RepoURLTypeFile),
|
||||
"--path", guestbookPath, "--project", proj.Name, "--dest-server", v1alpha1.KubernetesInternalAPIServerAddr, "--dest-namespace", fixture.DeploymentNamespace())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Waiting for the app to be successfully created.
|
||||
// Else the sync would fail to retrieve the app resources.
|
||||
@@ -611,7 +612,7 @@ func TestGetVirtualProjectMatch(t *testing.T) {
|
||||
|
||||
// App trying to sync a resource which is not blacked listed anywhere
|
||||
_, err = fixture.RunCli("app", "sync", fixture.Name(), "--resource", "apps:Deployment:guestbook-ui", "--timeout", fmt.Sprintf("%v", 10))
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "blocked by sync window")
|
||||
|
||||
// app trying to sync a resource which is black listed by global project
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
repositorypkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
|
||||
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
|
||||
@@ -20,15 +21,15 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
||||
app.Given(t).And(func() {
|
||||
repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile)
|
||||
_, err := fixture.RunCli("repo", "add", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
exists := false
|
||||
for i := range repo.Items {
|
||||
if repo.Items[i].Repo == repoUrl {
|
||||
@@ -39,10 +40,10 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
||||
assert.True(t, exists)
|
||||
|
||||
_, err = fixture.RunCli("repo", "rm", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
exists = false
|
||||
for i := range repo.Items {
|
||||
if repo.Items[i].Repo == repoUrl {
|
||||
@@ -66,7 +67,7 @@ func TestGetRepoWithInheritedCreds(t *testing.T) {
|
||||
|
||||
// Then, we remove username/password so that the repo inherits the credentials from our repocreds
|
||||
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
_, err = repoClient.UpdateRepository(context.Background(), &repositorypkg.RepoUpdateRequest{
|
||||
@@ -74,15 +75,15 @@ func TestGetRepoWithInheritedCreds(t *testing.T) {
|
||||
Repo: repoUrl,
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// CLI output should indicate that repo has inherited credentials
|
||||
out, err := fixture.RunCli("repo", "get", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "inherited")
|
||||
|
||||
_, err = fixture.RunCli("repo", "rm", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,13 +92,13 @@ func TestUpsertExistingRepo(t *testing.T) {
|
||||
fixture.SetRepos(settings.RepositoryCredentials{URL: fixture.RepoURL(fixture.RepoURLTypeFile)})
|
||||
repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile)
|
||||
_, err := fixture.RunCli("repo", "add", repoUrl)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("repo", "add", repoUrl, "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
|
||||
_, err = fixture.RunCli("repo", "add", repoUrl, "--upsert", "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,15 +111,15 @@ func TestAddRemoveHelmRepo(t *testing.T) {
|
||||
"--password", fixture.GitPassword,
|
||||
"--tls-client-cert-path", repos.CertPath,
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
exists := false
|
||||
for i := range repo.Items {
|
||||
if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) {
|
||||
@@ -129,10 +130,10 @@ func TestAddRemoveHelmRepo(t *testing.T) {
|
||||
assert.True(t, exists)
|
||||
|
||||
_, err = fixture.RunCli("repo", "rm", fixture.RepoURL(fixture.RepoURLTypeHelm))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
exists = false
|
||||
for i := range repo.Items {
|
||||
if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) {
|
||||
@@ -155,22 +156,16 @@ func TestAddHelmRepoInsecureSkipVerify(t *testing.T) {
|
||||
"--tls-client-cert-path", repos.CertPath,
|
||||
"--tls-client-cert-key-path", repos.CertKeyPath)
|
||||
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
exists := false
|
||||
for i := range repo.Items {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
|
||||
)
|
||||
@@ -13,7 +14,7 @@ func TestUserInfo(t *testing.T) {
|
||||
|
||||
output, err := RunCli("account", "get-user-info")
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, `Logged In: true
|
||||
Username: admin
|
||||
Issuer: argocd
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
argoexec "github.com/argoproj/pkg/exec"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/argoproj/argo-cd/v2/test/fixture/test"
|
||||
)
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
func TestKustomizeVersion(t *testing.T) {
|
||||
test.CIOnly(t)
|
||||
out, err := argoexec.RunCommand("kustomize", argoexec.CmdOpts{}, "version")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, out, "v5.", "kustomize should be version 5")
|
||||
}
|
||||
|
||||
@@ -41,5 +42,5 @@ func TestBuildManifests(t *testing.T) {
|
||||
_, err = argoexec.RunCommand("kustomize", argoexec.CmdOpts{}, "build", dirName)
|
||||
return err
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user