chore: refactor test functions to pass context from testing.T to fixtures (#25134)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-11-02 13:39:24 +01:00
committed by GitHub
parent f26533ab37
commit 4ea276860c
15 changed files with 244 additions and 246 deletions

View File

@@ -223,7 +223,7 @@ func TestTransForm(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
testGenerators := map[string]Generator{
"Clusters": getMockClusterGenerator(),
"Clusters": getMockClusterGenerator(t.Context()),
}
applicationSetInfo := argov1alpha1.ApplicationSet{
@@ -260,7 +260,7 @@ func emptyTemplate() argov1alpha1.ApplicationSetTemplate {
}
}
func getMockClusterGenerator() Generator {
func getMockClusterGenerator(ctx context.Context) Generator {
clusters := []crtclient.Object{
&corev1.Secret{
TypeMeta: metav1.TypeMeta{
@@ -342,7 +342,7 @@ func getMockClusterGenerator() Generator {
appClientset := kubefake.NewSimpleClientset(runtimeClusters...)
fakeClient := fake.NewClientBuilder().WithObjects(clusters...).Build()
return NewClusterGenerator(context.Background(), fakeClient, appClientset, "namespace")
return NewClusterGenerator(ctx, fakeClient, appClientset, "namespace")
}
func getMockGitGenerator() Generator {
@@ -354,7 +354,7 @@ func getMockGitGenerator() Generator {
func TestGetRelevantGenerators(t *testing.T) {
testGenerators := map[string]Generator{
"Clusters": getMockClusterGenerator(),
"Clusters": getMockClusterGenerator(t.Context()),
"Git": getMockGitGenerator(),
}

View File

@@ -1,7 +1,6 @@
package services
import (
"context"
"crypto/tls"
"net/http"
"testing"
@@ -12,7 +11,7 @@ import (
)
func TestSetupBitbucketClient(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
cfg := &bitbucketv1.Configuration{}
// Act

View File

@@ -40,9 +40,7 @@ func captureStdout(callback func()) (string, error) {
return string(data), err
}
func newSettingsManager(data map[string]string) *settings.SettingsManager {
ctx := context.Background()
func newSettingsManager(ctx context.Context, data map[string]string) *settings.SettingsManager {
clientset := fake.NewClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
@@ -69,8 +67,8 @@ type fakeCmdContext struct {
mgr *settings.SettingsManager
}
func newCmdContext(data map[string]string) *fakeCmdContext {
return &fakeCmdContext{mgr: newSettingsManager(data)}
func newCmdContext(ctx context.Context, data map[string]string) *fakeCmdContext {
return &fakeCmdContext{mgr: newSettingsManager(ctx, data)}
}
func (ctx *fakeCmdContext) createSettingsManager(context.Context) (*settings.SettingsManager, error) {
@@ -182,7 +180,7 @@ admissionregistration.k8s.io/MutatingWebhookConfiguration:
if !assert.True(t, ok) {
return
}
summary, err := validator(newSettingsManager(tc.data))
summary, err := validator(newSettingsManager(t.Context(), tc.data))
if tc.containsSummary != "" {
require.NoError(t, err)
assert.Contains(t, summary, tc.containsSummary)
@@ -249,7 +247,7 @@ func tempFile(content string) (string, io.Closer, error) {
}
func TestValidateSettingsCommand_NoErrors(t *testing.T) {
cmd := NewValidateSettingsCommand(newCmdContext(map[string]string{}))
cmd := NewValidateSettingsCommand(newCmdContext(t.Context(), map[string]string{}))
out, err := captureStdout(func() {
err := cmd.Execute()
require.NoError(t, err)
@@ -267,7 +265,7 @@ func TestResourceOverrideIgnoreDifferences(t *testing.T) {
defer utilio.Close(closer)
t.Run("NoOverridesConfigured", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{}))
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{}))
out, err := captureStdout(func() {
cmd.SetArgs([]string{"ignore-differences", f})
err := cmd.Execute()
@@ -278,7 +276,7 @@ func TestResourceOverrideIgnoreDifferences(t *testing.T) {
})
t.Run("DataIgnored", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `apps/Deployment:
ignoreDifferences: |
jsonPointers:
@@ -300,7 +298,7 @@ func TestResourceOverrideHealth(t *testing.T) {
defer utilio.Close(closer)
t.Run("NoHealthAssessment", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `example.com/ExampleResource: {}`,
}))
out, err := captureStdout(func() {
@@ -313,7 +311,7 @@ func TestResourceOverrideHealth(t *testing.T) {
})
t.Run("HealthAssessmentConfigured", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `example.com/ExampleResource:
health.lua: |
return { status = "Progressing" }
@@ -329,7 +327,7 @@ func TestResourceOverrideHealth(t *testing.T) {
})
t.Run("HealthAssessmentConfiguredWildcard", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `example.com/*:
health.lua: |
return { status = "Progressing" }
@@ -355,7 +353,7 @@ func TestResourceOverrideAction(t *testing.T) {
defer utilio.Close(closer)
t.Run("NoActions", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `apps/Deployment: {}`,
}))
out, err := captureStdout(func() {
@@ -368,7 +366,7 @@ func TestResourceOverrideAction(t *testing.T) {
})
t.Run("OldStyleActionConfigured", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `apps/Deployment:
actions: |
discovery.lua: |
@@ -404,7 +402,7 @@ resume false
})
t.Run("NewStyleActionConfigured", func(t *testing.T) {
cmd := NewResourceOverridesCommand(newCmdContext(map[string]string{
cmd := NewResourceOverridesCommand(newCmdContext(t.Context(), map[string]string{
"resource.customizations": `batch/CronJob:
actions: |
discovery.lua: |

View File

@@ -95,11 +95,11 @@ func (m *MockKubectl) DeleteResource(ctx context.Context, config *rest.Config, g
return m.Kubectl.DeleteResource(ctx, config, gvk, name, namespace, deleteOptions)
}
func newFakeController(data *fakeData, repoErr error) *ApplicationController {
return newFakeControllerWithResync(data, time.Minute, repoErr, nil)
func newFakeController(ctx context.Context, data *fakeData, repoErr error) *ApplicationController {
return newFakeControllerWithResync(ctx, data, time.Minute, repoErr, nil)
}
func newFakeControllerWithResync(data *fakeData, appResyncPeriod time.Duration, repoErr, revisionPathsErr error) *ApplicationController {
func newFakeControllerWithResync(ctx context.Context, data *fakeData, appResyncPeriod time.Duration, repoErr, revisionPathsErr error) *ApplicationController {
var clust corev1.Secret
err := yaml.Unmarshal([]byte(fakeCluster), &clust)
if err != nil {
@@ -158,7 +158,7 @@ func newFakeControllerWithResync(data *fakeData, appResyncPeriod time.Duration,
runtimeObjs := []runtime.Object{&clust, &secret, &cm}
runtimeObjs = append(runtimeObjs, data.additionalObjs...)
kubeClient := fake.NewClientset(runtimeObjs...)
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClient, test.FakeArgoCDNamespace)
settingsMgr := settings.NewSettingsManager(ctx, kubeClient, test.FakeArgoCDNamespace)
kubectl := &MockKubectl{Kubectl: &kubetest.MockKubectlCmd{}}
ctrl, err := NewApplicationController(
test.FakeArgoCDNamespace,
@@ -595,7 +595,7 @@ func newFakeServiceAccount() map[string]any {
func TestAutoSync(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -613,7 +613,7 @@ func TestAutoSyncEnabledSetToTrue(t *testing.T) {
app := newFakeApp()
enable := true
app.Spec.SyncPolicy.Automated = &v1alpha1.SyncPolicyAutomated{Enabled: &enable}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -634,7 +634,7 @@ func TestAutoSyncMultiSourceWithoutSelfHeal(t *testing.T) {
app := newFakeMultiSourceApp()
app.Spec.SyncPolicy.Automated.SelfHeal = false
app.Status.OperationState.SyncResult.Revisions = []string{"z", "x", "v"}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revisions: []string{"z", "x", "v"},
@@ -649,7 +649,7 @@ func TestAutoSyncMultiSourceWithoutSelfHeal(t *testing.T) {
app := newFakeMultiSourceApp()
app.Spec.SyncPolicy.Automated.SelfHeal = false
app.Status.OperationState.SyncResult.Revisions = []string{"z", "x", "v"}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revisions: []string{"a", "b", "c"},
@@ -665,7 +665,7 @@ func TestAutoSyncMultiSourceWithoutSelfHeal(t *testing.T) {
func TestAutoSyncNotAllowEmpty(t *testing.T) {
app := newFakeApp()
app.Spec.SyncPolicy.Automated.Prune = true
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -678,7 +678,7 @@ func TestAutoSyncAllowEmpty(t *testing.T) {
app := newFakeApp()
app.Spec.SyncPolicy.Automated.Prune = true
app.Spec.SyncPolicy.Automated.AllowEmpty = true
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -692,7 +692,7 @@ func TestSkipAutoSync(t *testing.T) {
// Set current to 'aaaaa', desired to 'aaaa' and mark system OutOfSync
t.Run("PreviouslySyncedToRevision", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -707,7 +707,7 @@ func TestSkipAutoSync(t *testing.T) {
// Verify we skip when we are already Synced (even if revision is different)
t.Run("AlreadyInSyncedState", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeSynced,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -723,7 +723,7 @@ func TestSkipAutoSync(t *testing.T) {
t.Run("AutoSyncIsDisabled", func(t *testing.T) {
app := newFakeApp()
app.Spec.SyncPolicy = nil
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -740,7 +740,7 @@ func TestSkipAutoSync(t *testing.T) {
app := newFakeApp()
enable := false
app.Spec.SyncPolicy.Automated = &v1alpha1.SyncPolicyAutomated{Enabled: &enable}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -757,7 +757,7 @@ func TestSkipAutoSync(t *testing.T) {
app := newFakeApp()
now := metav1.Now()
app.DeletionTimestamp = &now
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -783,7 +783,7 @@ func TestSkipAutoSync(t *testing.T) {
Source: *app.Spec.Source.DeepCopy(),
},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -807,7 +807,7 @@ func TestSkipAutoSync(t *testing.T) {
Source: *app.Spec.Source.DeepCopy(),
},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -821,7 +821,7 @@ func TestSkipAutoSync(t *testing.T) {
t.Run("NeedsToPruneResourcesOnlyButAutomatedPruneDisabled", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
@@ -847,7 +847,7 @@ func TestAutoSyncIndicateError(t *testing.T) {
},
},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
syncStatus := v1alpha1.SyncStatus{
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -907,7 +907,7 @@ func TestAutoSyncParameterOverrides(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
@@ -925,7 +925,7 @@ func TestAutoSyncParameterOverrides(t *testing.T) {
},
},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
app.Status.OperationState.SyncResult.Revisions = []string{"z", "x", "v"}
app.Status.OperationState.SyncResult.Sources[0].Helm = &v1alpha1.ApplicationSourceHelm{
Parameters: []v1alpha1.HelmParameter{
@@ -972,7 +972,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
app.SetCascadedDeletion(v1alpha1.ResourcesFinalizerName)
app.DeletionTimestamp = &now
app.Spec.Destination.Namespace = test.FakeArgoCDNamespace
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{}}, nil)
patched := false
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
defaultReactor := fakeAppCs.ReactionChain[0]
@@ -1017,7 +1017,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
appObj := kube.MustToUnstructured(&app)
cm := newFakeCM()
strayObj := kube.MustToUnstructured(&cm)
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj, &restrictedProj},
managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{
kube.GetResourceKey(appObj): appObj,
@@ -1058,7 +1058,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
app := newFakeAppWithDestName()
app.SetCascadedDeletion(v1alpha1.ResourcesFinalizerName)
app.DeletionTimestamp = &now
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{}}, nil)
patched := false
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
defaultReactor := fakeAppCs.ReactionChain[0]
@@ -1084,7 +1084,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
testShouldDelete := func(app *v1alpha1.Application) {
appObj := kube.MustToUnstructured(&app)
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}, managedLiveObjs: map[kube.ResourceKey]*unstructured.Unstructured{
kube.GetResourceKey(appObj): appObj,
}}, nil)
@@ -1118,7 +1118,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
app := newFakeApp()
app.SetPostDeleteFinalizer()
app.Spec.Destination.Namespace = test.FakeArgoCDNamespace
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
manifestResponses: []*apiclient.ManifestResponse{{
Manifests: []string{fakePostDeleteHook},
}},
@@ -1160,7 +1160,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
},
}
require.NoError(t, unstructured.SetNestedField(liveHook.Object, conditions, "status", "conditions"))
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
manifestResponses: []*apiclient.ManifestResponse{{
Manifests: []string{fakePostDeleteHook},
}},
@@ -1204,7 +1204,7 @@ func TestFinalizeAppDeletion(t *testing.T) {
},
}
require.NoError(t, unstructured.SetNestedField(liveHook.Object, conditions, "status", "conditions"))
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
manifestResponses: []*apiclient.ManifestResponse{{
Manifests: []string{fakeRoleBinding, fakeRole, fakeServiceAccount, fakePostDeleteHook},
}},
@@ -1306,7 +1306,7 @@ func TestFinalizeAppDeletionWithImpersonation(t *testing.T) {
},
additionalObjs: additionalObjs,
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
controller: ctrl,
@@ -1389,7 +1389,7 @@ func TestNormalizeApplication(t *testing.T) {
{
// Verify we normalize the app because project is missing
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
key, _ := cache.MetaNamespaceKeyFunc(app)
ctrl.appRefreshQueue.AddRateLimited(key)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
@@ -1411,7 +1411,7 @@ func TestNormalizeApplication(t *testing.T) {
// Verify we don't unnecessarily normalize app when project is set
app.Spec.Project = "default"
data.apps[0] = app
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
key, _ := cache.MetaNamespaceKeyFunc(app)
ctrl.appRefreshQueue.AddRateLimited(key)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
@@ -1436,7 +1436,7 @@ func TestHandleAppUpdated(t *testing.T) {
app.Spec.Destination.Server = v1alpha1.KubernetesInternalAPIServerAddr
proj := defaultProj.DeepCopy()
proj.Spec.SourceNamespaces = []string{test.FakeArgoCDNamespace}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, proj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, proj}}, nil)
ctrl.handleObjectUpdated(map[string]bool{app.InstanceName(ctrl.namespace): true}, kube.GetObjectRef(kube.MustToUnstructured(app)))
isRequested, level := ctrl.isRefreshRequested(app.QualifiedName())
@@ -1463,7 +1463,7 @@ func TestHandleOrphanedResourceUpdated(t *testing.T) {
proj := defaultProj.DeepCopy()
proj.Spec.OrphanedResources = &v1alpha1.OrphanedResourcesMonitorSettings{}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app1, app2, proj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app1, app2, proj}}, nil)
ctrl.handleObjectUpdated(map[string]bool{}, corev1.ObjectReference{UID: "test", Kind: kube.DeploymentKind, Name: "test", Namespace: test.FakeArgoCDNamespace})
@@ -1494,7 +1494,7 @@ func TestGetResourceTree_HasOrphanedResources(t *testing.T) {
ResourceRef: v1alpha1.ResourceRef{Group: "apps", Kind: "Deployment", Namespace: "default", Name: "deploy2"},
}
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, proj},
namespacedResources: map[kube.ResourceKey]namespacedResource{
kube.NewResourceKey("apps", "Deployment", "default", "nginx-deployment"): {ResourceNode: managedDeploy},
@@ -1517,7 +1517,7 @@ func TestGetResourceTree_HasOrphanedResources(t *testing.T) {
}
func TestSetOperationStateOnDeletedApp(t *testing.T) {
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
fakeAppCs.ReactionChain = nil
patched := false
@@ -1535,7 +1535,7 @@ func TestSetOperationStateLogRetries(t *testing.T) {
t.Cleanup(func() {
logrus.StandardLogger().ReplaceHooks(logrus.LevelHooks{})
})
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
fakeAppCs.ReactionChain = nil
patched := false
@@ -1591,7 +1591,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
app.Status.Sync.ComparedTo.Source = app.Spec.GetSource()
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
t.Run("no need to refresh just reconciled application", func(t *testing.T) {
needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour)
@@ -1603,7 +1603,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
assert.False(t, needRefresh)
// use a one-off controller so other tests don't have a manual refresh request
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
// refresh app using the 'deepest' requested comparison level
ctrl.requestAppRefresh(app.Name, CompareWithRecent.Pointer(), nil)
@@ -1620,7 +1620,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
assert.False(t, needRefresh)
// use a one-off controller so other tests don't have a manual refresh request
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
// refresh app with a non-nil delay
// use zero-second delay to test the add later logic without waiting in the test
@@ -1650,7 +1650,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
app := app.DeepCopy()
// use a one-off controller so other tests don't have a manual refresh request
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour)
assert.False(t, needRefresh)
@@ -1680,7 +1680,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
}
// use a one-off controller so other tests don't have a manual refresh request
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
needRefresh, _, _ := ctrl.needRefreshAppStatus(app, 1*time.Hour, 2*time.Hour)
assert.False(t, needRefresh)
@@ -1760,7 +1760,7 @@ func TestNeedRefreshAppStatus(t *testing.T) {
}
func TestUpdatedManagedNamespaceMetadata(t *testing.T) {
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
app := newFakeApp()
app.Spec.SyncPolicy.ManagedNamespaceMetadata = &v1alpha1.ManagedNamespaceMetadata{
Labels: map[string]string{
@@ -1784,7 +1784,7 @@ func TestUpdatedManagedNamespaceMetadata(t *testing.T) {
}
func TestUnchangedManagedNamespaceMetadata(t *testing.T) {
ctrl := newFakeController(&fakeData{apps: []runtime.Object{}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{}}, nil)
app := newFakeApp()
app.Spec.SyncPolicy.ManagedNamespaceMetadata = &v1alpha1.ManagedNamespaceMetadata{
Labels: map[string]string{
@@ -1827,7 +1827,7 @@ func TestRefreshAppConditions(t *testing.T) {
t.Run("NoErrorConditions", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
_, hasErrors := ctrl.refreshAppConditions(app)
assert.False(t, hasErrors)
@@ -1838,7 +1838,7 @@ func TestRefreshAppConditions(t *testing.T) {
app := newFakeApp()
app.Status.SetConditions([]v1alpha1.ApplicationCondition{{Type: v1alpha1.ApplicationConditionExcludedResourceWarning}}, nil)
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
_, hasErrors := ctrl.refreshAppConditions(app)
assert.False(t, hasErrors)
@@ -1851,7 +1851,7 @@ func TestRefreshAppConditions(t *testing.T) {
app.Spec.Project = "wrong project"
app.Status.SetConditions([]v1alpha1.ApplicationCondition{{Type: v1alpha1.ApplicationConditionInvalidSpecError, Message: "old message"}}, nil)
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &defaultProj}}, nil)
_, hasErrors := ctrl.refreshAppConditions(app)
assert.True(t, hasErrors)
@@ -1866,7 +1866,7 @@ func TestUpdateReconciledAt(t *testing.T) {
reconciledAt := metav1.NewTime(time.Now().Add(-1 * time.Second))
app.Status = v1alpha1.ApplicationStatus{ReconciledAt: &reconciledAt}
app.Status.Sync = v1alpha1.SyncStatus{ComparedTo: v1alpha1.ComparedTo{Source: app.Spec.GetSource(), Destination: app.Spec.Destination, IgnoreDifferences: app.Spec.IgnoreDifferences}}
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -1997,7 +1997,7 @@ apps/Deployment:
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{tc.app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -2061,7 +2061,7 @@ apps/Deployment:
return hs`,
}
ctrl := newFakeControllerWithResync(&fakeData{
ctrl := newFakeControllerWithResync(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -2128,7 +2128,7 @@ apps/Deployment:
func TestProjectErrorToCondition(t *testing.T) {
app := newFakeApp()
app.Spec.Project = "wrong project"
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -2156,7 +2156,7 @@ func TestProjectErrorToCondition(t *testing.T) {
func TestFinalizeProjectDeletion_HasApplications(t *testing.T) {
app := newFakeApp()
proj := &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: test.FakeArgoCDNamespace}}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, proj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, proj}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
patched := false
@@ -2172,7 +2172,7 @@ func TestFinalizeProjectDeletion_HasApplications(t *testing.T) {
func TestFinalizeProjectDeletion_DoesNotHaveApplications(t *testing.T) {
proj := &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: test.FakeArgoCDNamespace}}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{&defaultProj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{&defaultProj}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
@@ -2198,7 +2198,7 @@ func TestProcessRequestedAppOperation_FailedNoRetries(t *testing.T) {
app.Operation = &v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
@@ -2225,7 +2225,7 @@ func TestProcessRequestedAppOperation_InvalidDestination(t *testing.T) {
proj := defaultProj
proj.Name = "test-project"
proj.Spec.SourceNamespaces = []string{test.FakeArgoCDNamespace}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app, &proj}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app, &proj}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
func() {
@@ -2254,7 +2254,7 @@ func TestProcessRequestedAppOperation_FailedHasRetries(t *testing.T) {
Sync: &v1alpha1.SyncOperation{},
Retry: v1alpha1.RetryStrategy{Limit: 1},
}
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
@@ -2301,7 +2301,7 @@ func TestProcessRequestedAppOperation_RunningPreviouslyFailed(t *testing.T) {
Revision: "abc123",
},
}
ctrl := newFakeController(data, nil)
ctrl := newFakeController(t.Context(), data, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
@@ -2358,7 +2358,7 @@ func TestProcessRequestedAppOperation_RunningPreviouslyFailedBackoff(t *testing.
Revision: "abc123",
},
}
ctrl := newFakeController(data, nil)
ctrl := newFakeController(t.Context(), data, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
fakeAppCs.PrependReactor("patch", "*", func(_ kubetesting.Action) (handled bool, ret runtime.Object, err error) {
require.FailNow(t, "A patch should not have been called if the backoff has not passed")
@@ -2386,7 +2386,7 @@ func TestProcessRequestedAppOperation_HasRetriesTerminated(t *testing.T) {
Revision: "abc123",
},
}
ctrl := newFakeController(data, nil)
ctrl := newFakeController(t.Context(), data, nil)
fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset)
receivedPatch := map[string]any{}
fakeAppCs.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
@@ -2410,7 +2410,7 @@ func TestProcessRequestedAppOperation_Successful(t *testing.T) {
app.Operation = &v1alpha1.Operation{
Sync: &v1alpha1.SyncOperation{},
}
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponses: []*apiclient.ManifestResponse{{
Manifests: []string{},
@@ -2485,7 +2485,7 @@ func TestProcessRequestedAppOperation_SyncTimeout(t *testing.T) {
Revision: "HEAD",
},
}
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponses: []*apiclient.ManifestResponse{{
Manifests: []string{},
@@ -2527,7 +2527,7 @@ func TestGetAppHosts(t *testing.T) {
"application.allowedNodeLabels": "label1,label2",
},
}
ctrl := newFakeController(data, nil)
ctrl := newFakeController(t.Context(), data, nil)
mockStateCache := &mockstatecache.LiveStateCache{}
mockStateCache.EXPECT().IterateResources(mock.Anything, mock.MatchedBy(func(callback func(res *clustercache.Resource, info *statecache.ResourceInfo)) bool {
// node resource
@@ -2582,15 +2582,15 @@ func TestGetAppHosts(t *testing.T) {
func TestMetricsExpiration(t *testing.T) {
app := newFakeApp()
// Check expiration is disabled by default
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
assert.False(t, ctrl.metricsServer.HasExpiration())
// Check expiration is enabled if set
ctrl = newFakeController(&fakeData{apps: []runtime.Object{app}, metricsCacheExpiration: 10 * time.Second}, nil)
ctrl = newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}, metricsCacheExpiration: 10 * time.Second}, nil)
assert.True(t, ctrl.metricsServer.HasExpiration())
}
func TestToAppKey(t *testing.T) {
ctrl := newFakeController(&fakeData{}, nil)
ctrl := newFakeController(t.Context(), &fakeData{}, nil)
tests := []struct {
name string
input string
@@ -2610,7 +2610,7 @@ func TestToAppKey(t *testing.T) {
func Test_canProcessApp(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
ctrl.applicationNamespaces = []string{"good"}
t.Run("without cluster filter, good namespace", func(t *testing.T) {
app.Namespace = "good"
@@ -2641,7 +2641,7 @@ func Test_canProcessAppSkipReconcileAnnotation(t *testing.T) {
appSkipReconcileFalse.Annotations = map[string]string{common.AnnotationKeyAppSkipReconcile: "false"}
appSkipReconcileTrue := newFakeApp()
appSkipReconcileTrue.Annotations = map[string]string{common.AnnotationKeyAppSkipReconcile: "true"}
ctrl := newFakeController(&fakeData{}, nil)
ctrl := newFakeController(t.Context(), &fakeData{}, nil)
tests := []struct {
name string
input any
@@ -2662,7 +2662,7 @@ func Test_canProcessAppSkipReconcileAnnotation(t *testing.T) {
func Test_syncDeleteOption(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{apps: []runtime.Object{app}}, nil)
ctrl := newFakeController(t.Context(), &fakeData{apps: []runtime.Object{app}}, nil)
cm := newFakeCM()
t.Run("without delete option object is deleted", func(t *testing.T) {
cmObj := kube.MustToUnstructured(&cm)
@@ -2683,7 +2683,7 @@ func Test_syncDeleteOption(t *testing.T) {
func TestAddControllerNamespace(t *testing.T) {
t.Run("set controllerNamespace when the app is in the controller namespace", func(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{},
}, nil)
@@ -2701,7 +2701,7 @@ func TestAddControllerNamespace(t *testing.T) {
app.Namespace = appNamespace
proj := defaultProj
proj.Spec.SourceNamespaces = []string{appNamespace}
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &proj},
manifestResponse: &apiclient.ManifestResponse{},
applicationNamespaces: []string{appNamespace},
@@ -2958,7 +2958,7 @@ func assertDurationAround(t *testing.T, expected time.Duration, actual time.Dura
}
func TestSelfHealRemainingBackoff(t *testing.T) {
ctrl := newFakeController(&fakeData{}, nil)
ctrl := newFakeController(t.Context(), &fakeData{}, nil)
ctrl.selfHealBackoff = &wait.Backoff{
Factor: 3,
Duration: 2 * time.Second,
@@ -3040,7 +3040,7 @@ func TestSelfHealRemainingBackoff(t *testing.T) {
func TestSelfHealBackoffCooldownElapsed(t *testing.T) {
cooldown := time.Second * 30
ctrl := newFakeController(&fakeData{}, nil)
ctrl := newFakeController(t.Context(), &fakeData{}, nil)
ctrl.selfHealBackoffCooldown = cooldown
app := &v1alpha1.Application{

View File

@@ -40,7 +40,7 @@ func (n netError) Error() string { return string(n) }
func (n netError) Timeout() bool { return false }
func (n netError) Temporary() bool { return false }
func fixtures(data map[string]string, opts ...func(secret *corev1.Secret)) (*fake.Clientset, *argosettings.SettingsManager) {
func fixtures(ctx context.Context, data map[string]string, opts ...func(secret *corev1.Secret)) (*fake.Clientset, *argosettings.SettingsManager) {
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: common.ArgoCDConfigMapName,
@@ -65,7 +65,7 @@ func fixtures(data map[string]string, opts ...func(secret *corev1.Secret)) (*fak
opts[i](secret)
}
kubeClient := fake.NewClientset(cm, secret)
settingsManager := argosettings.NewSettingsManager(context.Background(), kubeClient, "default")
settingsManager := argosettings.NewSettingsManager(ctx, kubeClient, "default")
return kubeClient, settingsManager
}
@@ -775,7 +775,7 @@ func Test_GetVersionsInfo_error_redacted(t *testing.T) {
}
func TestLoadCacheSettings(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.instanceLabelKey": "testLabel",
"application.resourceTrackingMethod": string(appv1.TrackingMethodLabel),
"installationID": "123456789",

View File

@@ -1055,7 +1055,7 @@ func TestHydrator_getManifests_Success(t *testing.T) {
Commands: []string{"cmd1", "cmd2"},
}, nil)
rev, pathDetails, err := h.getManifests(context.Background(), app, "sha123", proj)
rev, pathDetails, err := h.getManifests(t.Context(), app, "sha123", proj)
require.NoError(t, err)
assert.Equal(t, "sha123", rev)
assert.Equal(t, app.Spec.SourceHydrator.SyncSource.Path, pathDetails.Path)
@@ -1073,7 +1073,7 @@ func TestHydrator_getManifests_EmptyTargetRevision(t *testing.T) {
d.EXPECT().GetRepoObjs(mock.Anything, app, mock.Anything, "main", proj).Return([]*unstructured.Unstructured{}, &repoclient.ManifestResponse{Revision: "sha123"}, nil)
rev, pathDetails, err := h.getManifests(context.Background(), app, "", proj)
rev, pathDetails, err := h.getManifests(t.Context(), app, "", proj)
require.NoError(t, err)
assert.Equal(t, "sha123", rev)
assert.NotNil(t, pathDetails)
@@ -1088,7 +1088,7 @@ func TestHydrator_getManifests_GetRepoObjsError(t *testing.T) {
d.EXPECT().GetRepoObjs(mock.Anything, app, mock.Anything, "main", proj).Return(nil, nil, errors.New("repo error"))
rev, pathDetails, err := h.getManifests(context.Background(), app, "main", proj)
rev, pathDetails, err := h.getManifests(t.Context(), app, "main", proj)
require.Error(t, err)
assert.Contains(t, err.Error(), "repo error")
assert.Empty(t, rev)

View File

@@ -43,7 +43,7 @@ func TestGetRepoObjs(t *testing.T) {
},
}
ctrl := newFakeControllerWithResync(&data, time.Minute, nil, errors.New("this should not be called"))
ctrl := newFakeControllerWithResync(t.Context(), &data, time.Minute, nil, errors.New("this should not be called"))
source := app.Spec.GetSource()
source.RepoURL = "oci://example.com/argo/argo-cd"
@@ -92,7 +92,7 @@ func TestGetHydratorCommitMessageTemplate_WhenTemplateisNotDefined_FallbackToDef
},
}
ctrl := newFakeControllerWithResync(&data, time.Minute, nil, errors.New("this should not be called"))
ctrl := newFakeControllerWithResync(t.Context(), &data, time.Minute, nil, errors.New("this should not be called"))
tmpl, err := ctrl.GetHydratorCommitMessageTemplate()
require.NoError(t, err)
@@ -115,7 +115,7 @@ func TestGetHydratorCommitMessageTemplate(t *testing.T) {
configMapData: cm.Data,
}
ctrl := newFakeControllerWithResync(&data, time.Minute, nil, errors.New("this should not be called"))
ctrl := newFakeControllerWithResync(t.Context(), &data, time.Minute, nil, errors.New("this should not be called"))
tmpl, err := ctrl.GetHydratorCommitMessageTemplate()
require.NoError(t, err)

View File

@@ -263,8 +263,8 @@ func newFakeApp(fakeAppYAML string) *argoappv1.Application {
return &app
}
func newFakeLister(fakeAppYAMLs ...string) (context.CancelFunc, applister.ApplicationLister) {
ctx, cancel := context.WithCancel(context.Background())
func newFakeLister(ctx context.Context, fakeAppYAMLs ...string) (context.CancelFunc, applister.ApplicationLister) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
var fakeApps []runtime.Object
for _, appYAML := range fakeAppYAMLs {
@@ -319,7 +319,7 @@ func testMetricServer(t *testing.T, fakeAppYAMLs []string, expectedResponse stri
func runTest(t *testing.T, cfg TestMetricServerConfig) {
t.Helper()
cancel, appLister := newFakeLister(cfg.FakeAppYAMLs...)
cancel, appLister := newFakeLister(t.Context(), cfg.FakeAppYAMLs...)
defer cancel()
mockDB := mocks.NewArgoDB(t)
mockDB.EXPECT().GetClusterServersByName(mock.Anything, "cluster1").Return([]string{"https://localhost:6443"}, nil).Maybe()
@@ -472,7 +472,7 @@ argocd_app_condition{condition="ExcludedResourceWarning",name="my-app-4",namespa
}
func TestMetricsSyncCounter(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -526,7 +526,7 @@ func assertMetricsNotPrinted(t *testing.T, expectedLines, body string) {
}
func TestMetricsSyncDuration(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -567,7 +567,7 @@ argocd_app_sync_duration_seconds_total{dest_server="https://localhost:6443",name
}
func TestReconcileMetrics(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -601,7 +601,7 @@ argocd_app_reconcile_count{dest_server="https://localhost:6443",namespace="argoc
}
func TestOrphanedResourcesMetric(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -627,7 +627,7 @@ argocd_app_orphaned_resources_count{name="my-app-4",namespace="argocd",project="
}
func TestMetricsReset(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -665,7 +665,7 @@ argocd_app_sync_total{dest_server="https://localhost:6443",dry_run="false",name=
}
func TestWorkqueueMetrics(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
@@ -696,7 +696,7 @@ workqueue_unfinished_work_seconds{controller="test",name="test"}
}
func TestGoMetrics(t *testing.T) {
cancel, appLister := newFakeLister()
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)

View File

@@ -48,7 +48,7 @@ func TestCompareAppStateEmpty(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -66,7 +66,7 @@ func TestCompareAppStateEmpty(t *testing.T) {
// TestCompareAppStateRepoError tests the case when CompareAppState notices a repo error
func TestCompareAppStateRepoError(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{manifestResponses: make([]*apiclient.ManifestResponse, 3)}, errors.New("test repo error"))
ctrl := newFakeController(t.Context(), &fakeData{manifestResponses: make([]*apiclient.ManifestResponse, 3)}, errors.New("test repo error"))
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -112,7 +112,7 @@ func TestCompareAppStateNamespaceMetadataDiffers(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -161,7 +161,7 @@ func TestCompareAppStateNamespaceMetadataDiffersToManifest(t *testing.T) {
kube.GetResourceKey(ns): ns,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -219,7 +219,7 @@ func TestCompareAppStateNamespaceMetadata(t *testing.T) {
kube.GetResourceKey(ns): ns,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -278,7 +278,7 @@ func TestCompareAppStateNamespaceMetadataIsTheSame(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -306,7 +306,7 @@ func TestCompareAppStateMissing(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -338,7 +338,7 @@ func TestCompareAppStateExtra(t *testing.T) {
key: pod,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -369,7 +369,7 @@ func TestCompareAppStateHook(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -401,7 +401,7 @@ func TestCompareAppStateSkipHook(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -431,7 +431,7 @@ func TestCompareAppStateCompareOptionIgnoreExtraneous(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
@@ -465,7 +465,7 @@ func TestCompareAppStateExtraHook(t *testing.T) {
key: pod,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -494,7 +494,7 @@ func TestAppRevisionsSingleSource(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
app := newFakeApp()
revisions := make([]string, 0)
@@ -534,7 +534,7 @@ func TestAppRevisionsMultiSource(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
app := newFakeMultiSourceApp()
revisions := make([]string, 0)
@@ -583,7 +583,7 @@ func TestCompareAppStateDuplicatedNamespacedResources(t *testing.T) {
kube.GetResourceKey(obj3): obj3,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -624,7 +624,7 @@ func TestCompareAppStateManagedNamespaceMetadataWithLiveNsDoesNotGetPruned(t *te
kube.GetResourceKey(ns): ns,
},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, []string{}, app.Spec.Sources, false, false, nil, false)
require.NoError(t, err)
@@ -676,7 +676,7 @@ func TestCompareAppStateWithManifestGeneratePath(t *testing.T) {
updateRevisionForPathsResponse: &apiclient.UpdateRevisionForPathsResponse{},
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
revisions := make([]string, 0)
revisions = append(revisions, "abc123")
compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, app.Spec.GetSources(), false, false, nil, false)
@@ -698,7 +698,7 @@ func TestSetHealth(t *testing.T) {
Namespace: "default",
},
})
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -734,7 +734,7 @@ func TestPreserveStatusTimestamp(t *testing.T) {
Namespace: "default",
},
})
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -770,7 +770,7 @@ func TestSetHealthSelfReferencedApp(t *testing.T) {
Namespace: "default",
},
})
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -799,7 +799,7 @@ func TestSetManagedResourcesWithOrphanedResources(t *testing.T) {
proj.Spec.OrphanedResources = &v1alpha1.OrphanedResourcesMonitorSettings{}
app := newFakeApp()
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, proj},
namespacedResources: map[kube.ResourceKey]namespacedResource{
kube.NewResourceKey("apps", kube.DeploymentKind, app.Namespace, "guestbook"): {
@@ -828,7 +828,7 @@ func TestSetManagedResourcesWithResourcesOfAnotherApp(t *testing.T) {
app2 := newFakeApp()
app2.Name = "app2"
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app1, app2, proj},
namespacedResources: map[kube.ResourceKey]namespacedResource{
kube.NewResourceKey("apps", kube.DeploymentKind, app2.Namespace, "guestbook"): {
@@ -852,7 +852,7 @@ func TestReturnUnknownComparisonStateOnSettingLoadError(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, proj},
configMapData: map[string]string{
"resource.customizations": "invalid setting",
@@ -878,7 +878,7 @@ func TestSetManagedResourcesKnownOrphanedResourceExceptions(t *testing.T) {
app := newFakeApp()
app.Namespace = "default"
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, proj},
namespacedResources: map[kube.ResourceKey]namespacedResource{
kube.NewResourceKey("apps", kube.DeploymentKind, app.Namespace, "guestbook"): {
@@ -902,7 +902,7 @@ func TestSetManagedResourcesKnownOrphanedResourceExceptions(t *testing.T) {
func Test_appStateManager_persistRevisionHistory(t *testing.T) {
app := newFakeApp()
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app},
}, nil)
manager := ctrl.appStateManager.(*appStateManager)
@@ -1007,7 +1007,7 @@ func TestSignedResponseNoSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1034,7 +1034,7 @@ func TestSignedResponseNoSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1066,7 +1066,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1093,7 +1093,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1120,7 +1120,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1147,7 +1147,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1175,7 +1175,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
testProj := signedProj
testProj.Spec.SignatureKeys[0].KeyID = "4AEE18F83AFDEB24"
sources := make([]v1alpha1.ApplicationSource, 0)
@@ -1207,7 +1207,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
}
// it doesn't matter for our test whether local manifests are valid
localManifests := []string{"foobar"}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1237,7 +1237,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1267,7 +1267,7 @@ func TestSignedResponseSignatureRequired(t *testing.T) {
}
// it doesn't matter for our test whether local manifests are valid
localManifests := []string{""}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1395,7 +1395,7 @@ func TestIsLiveResourceManaged(t *testing.T) {
},
},
})
ctrl := newFakeController(&fakeData{
ctrl := newFakeController(t.Context(), &fakeData{
apps: []runtime.Object{app, &defaultProj},
manifestResponse: &apiclient.ManifestResponse{
Manifests: []string{},
@@ -1765,7 +1765,7 @@ func TestCompareAppStateDefaultRevisionUpdated(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1788,7 +1788,7 @@ func TestCompareAppStateRevisionUpdatedWithHelmSource(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
sources := make([]v1alpha1.ApplicationSource, 0)
sources = append(sources, app.Spec.GetSource())
revisions := make([]string, 0)
@@ -1838,7 +1838,7 @@ func TestCompareAppState_DoesNotCallUpdateRevisionForPaths_ForOCI(t *testing.T)
Revision: "abc123",
},
}
ctrl := newFakeControllerWithResync(&data, time.Minute, nil, errors.New("this should not be called"))
ctrl := newFakeControllerWithResync(t.Context(), &data, time.Minute, nil, errors.New("this should not be called"))
source := app.Spec.GetSource()
source.RepoURL = "oci://example.com/argo/argo-cd"

View File

@@ -75,7 +75,7 @@ func TestPersistRevisionHistory(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
@@ -121,7 +121,7 @@ func TestPersistManagedNamespaceMetadataState(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
@@ -152,7 +152,7 @@ func TestPersistRevisionHistoryRollback(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source specified
source := v1alpha1.ApplicationSource{
@@ -206,7 +206,7 @@ func TestSyncComparisonError(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
// Sync with source unspecified
opState := &v1alpha1.OperationState{Operation: v1alpha1.Operation{
@@ -263,7 +263,7 @@ func TestAppStateManager_SyncAppState(t *testing.T) {
},
managedLiveObjs: liveObjects,
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
@@ -350,7 +350,7 @@ func TestSyncWindowDeniesSync(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
@@ -1620,7 +1620,7 @@ func TestSyncWithImpersonate(t *testing.T) {
},
additionalObjs: additionalObjs,
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,
project: project,
@@ -1780,7 +1780,7 @@ func TestClientSideApplyMigration(t *testing.T) {
},
managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured),
}
ctrl := newFakeController(&data, nil)
ctrl := newFakeController(t.Context(), &data, nil)
return &fixture{
application: app,

View File

@@ -16,7 +16,7 @@ import (
const testNamespace = "default"
func fixtures(data map[string]string) (*fake.Clientset, *settings.SettingsManager) {
func fixtures(ctx context.Context, data map[string]string) (*fake.Clientset, *settings.SettingsManager) {
kubeClient := fake.NewClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: common.ArgoCDConfigMapName,
@@ -36,13 +36,13 @@ func fixtures(data map[string]string) (*fake.Clientset, *settings.SettingsManage
"server.secretkey": []byte("test"),
},
})
settingsManager := settings.NewSettingsManager(context.Background(), kubeClient, testNamespace)
settingsManager := settings.NewSettingsManager(ctx, kubeClient, testNamespace)
return kubeClient, settingsManager
}
func TestSettingsServer(t *testing.T) {
newServer := func(data map[string]string) *Server {
_, settingsMgr := fixtures(data)
_, settingsMgr := fixtures(t.Context(), data)
return NewServer(settingsMgr, nil, nil, false, false, false, false)
}

View File

@@ -445,7 +445,7 @@ func TestRemoveOrphanedIgnore(t *testing.T) {
assertProjHasEvent(t, proj, "update", argo.EventReasonResourceUpdated)
}
func createAndConfigGlobalProject() error {
func createAndConfigGlobalProject(ctx context.Context) error {
// Create global project
projectGlobalName := "proj-g-" + fixture.Name()
_, err := fixture.RunCli("proj", "create", projectGlobalName,
@@ -458,7 +458,7 @@ func createAndConfigGlobalProject() error {
return err
}
projGlobal, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectGlobalName, metav1.GetOptions{})
projGlobal, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(ctx, projectGlobalName, metav1.GetOptions{})
if err != nil {
return err
}
@@ -483,7 +483,7 @@ func createAndConfigGlobalProject() error {
win := &v1alpha1.SyncWindow{Kind: "deny", Schedule: "* * * * *", Duration: "1h", Applications: []string{"*"}}
projGlobal.Spec.SyncWindows = append(projGlobal.Spec.SyncWindows, win)
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(context.Background(), projGlobal, metav1.UpdateOptions{})
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(ctx, projGlobal, metav1.UpdateOptions{})
if err != nil {
return err
}
@@ -513,7 +513,7 @@ func createAndConfigGlobalProject() error {
func TestGetVirtualProjectNoMatch(t *testing.T) {
fixture.EnsureCleanState(t)
err := createAndConfigGlobalProject()
err := createAndConfigGlobalProject(t.Context())
require.NoError(t, err)
// Create project which does not match global project settings
@@ -544,7 +544,8 @@ func TestGetVirtualProjectNoMatch(t *testing.T) {
func TestGetVirtualProjectMatch(t *testing.T) {
fixture.EnsureCleanState(t)
err := createAndConfigGlobalProject()
ctx := t.Context()
err := createAndConfigGlobalProject(ctx)
require.NoError(t, err)
// Create project which matches global project settings
@@ -556,12 +557,12 @@ func TestGetVirtualProjectMatch(t *testing.T) {
"--orphaned-resources")
require.NoError(t, err)
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(ctx, projectName, metav1.GetOptions{})
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(t.Context(), proj, metav1.UpdateOptions{})
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(ctx, proj, metav1.UpdateOptions{})
require.NoError(t, err)
// Create an app belongs to proj project

View File

@@ -90,7 +90,7 @@ func TestBlockingDial_ProxyEnvironmentHandling(t *testing.T) {
clearProxyEnv(t)
applyProxyEnv(t, tt.proxyEnv)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second)
defer cancel()
conn, err := BlockingNewClient(ctx, "tcp", tt.address, nil)

View File

@@ -15,7 +15,7 @@ import (
)
func TestGetAccounts_NoAccountsConfigured(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
accounts, err := settingsManager.GetAccounts()
require.NoError(t, err)
@@ -25,7 +25,7 @@ func TestGetAccounts_NoAccountsConfigured(t *testing.T) {
}
func TestGetAccounts_HasConfiguredAccounts(t *testing.T) {
_, settingsManager := fixtures(map[string]string{"accounts.test": "apiKey"}, func(secret *corev1.Secret) {
_, settingsManager := fixtures(t.Context(), map[string]string{"accounts.test": "apiKey"}, func(secret *corev1.Secret) {
secret.Data["accounts.test.tokens"] = []byte(`[{"id":"123","iat":1583789194,"exp":1583789194}]`)
})
accounts, err := settingsManager.GetAccounts()
@@ -39,7 +39,7 @@ func TestGetAccounts_HasConfiguredAccounts(t *testing.T) {
}
func TestGetAccounts_DisableAccount(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"accounts.test": "apiKey",
"accounts.test.enabled": "false",
})
@@ -52,7 +52,7 @@ func TestGetAccounts_DisableAccount(t *testing.T) {
}
func TestGetAccount(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"accounts.test": "apiKey",
})
@@ -71,7 +71,7 @@ func TestGetAccount(t *testing.T) {
}
func TestGetAccount_WithInvalidToken(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"accounts.user1": "apiKey",
"accounts.invaliduser": "apiKey",
"accounts.user2": "apiKey",
@@ -93,7 +93,7 @@ func TestGetAccount_WithInvalidToken(t *testing.T) {
func TestGetAdminAccount(t *testing.T) {
mTime := time.Now().Format(time.RFC3339)
_, settingsManager := fixtures(nil, func(secret *corev1.Secret) {
_, settingsManager := fixtures(t.Context(), nil, func(secret *corev1.Secret) {
secret.Data["admin.password"] = []byte("admin-password")
secret.Data["admin.passwordMtime"] = []byte(mTime)
})
@@ -140,7 +140,7 @@ func TestTokenIndex_TokenDoesNotExist(t *testing.T) {
}
func TestAddAccount_AccountAdded(t *testing.T) {
clientset, settingsManager := fixtures(nil)
clientset, settingsManager := fixtures(t.Context(), nil)
mTime := time.Now()
addedAccount := Account{
Tokens: []Token{{ID: "123"}},
@@ -167,19 +167,19 @@ func TestAddAccount_AccountAdded(t *testing.T) {
}
func TestAddAccount_AlreadyExists(t *testing.T) {
_, settingsManager := fixtures(map[string]string{"accounts.test": "login"})
_, settingsManager := fixtures(t.Context(), map[string]string{"accounts.test": "login"})
err := settingsManager.AddAccount("test", Account{})
require.Error(t, err)
}
func TestAddAccount_CannotAddAdmin(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
err := settingsManager.AddAccount("admin", Account{})
require.Error(t, err)
}
func TestUpdateAccount_SuccessfullyUpdated(t *testing.T) {
clientset, settingsManager := fixtures(map[string]string{"accounts.test": "login"})
clientset, settingsManager := fixtures(t.Context(), map[string]string{"accounts.test": "login"})
mTime := time.Now()
err := settingsManager.UpdateAccount("test", func(account *Account) error {
@@ -207,7 +207,7 @@ func TestUpdateAccount_SuccessfullyUpdated(t *testing.T) {
}
func TestUpdateAccount_UpdateAdminPassword(t *testing.T) {
clientset, settingsManager := fixtures(nil)
clientset, settingsManager := fixtures(t.Context(), nil)
mTime := time.Now()
err := settingsManager.UpdateAccount("admin", func(account *Account) error {
@@ -225,7 +225,7 @@ func TestUpdateAccount_UpdateAdminPassword(t *testing.T) {
}
func TestUpdateAccount_AccountDoesNotExist(t *testing.T) {
_, settingsManager := fixtures(map[string]string{"accounts.test": "login"})
_, settingsManager := fixtures(t.Context(), map[string]string{"accounts.test": "login"})
err := settingsManager.UpdateAccount("test1", func(account *Account) error {
account.Enabled = false

View File

@@ -25,7 +25,7 @@ import (
"github.com/argoproj/argo-cd/v3/util/test"
)
func fixtures(data map[string]string, opts ...func(secret *corev1.Secret)) (*fake.Clientset, *SettingsManager) {
func fixtures(ctx context.Context, data map[string]string, opts ...func(secret *corev1.Secret)) (*fake.Clientset, *SettingsManager) {
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: common.ArgoCDConfigMapName,
@@ -50,7 +50,7 @@ func fixtures(data map[string]string, opts ...func(secret *corev1.Secret)) (*fak
opts[i](secret)
}
kubeClient := fake.NewClientset(cm, secret)
settingsManager := NewSettingsManager(context.Background(), kubeClient, "default")
settingsManager := NewSettingsManager(ctx, kubeClient, "default")
return kubeClient, settingsManager
}
@@ -67,13 +67,13 @@ func TestDocumentedArgoCDConfigMapIsValid(t *testing.T) {
func TestGetConfigMapByName(t *testing.T) {
t.Run("data is never nil", func(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
cm, err := settingsManager.GetConfigMapByName(common.ArgoCDConfigMapName)
require.NoError(t, err)
assert.NotNil(t, cm.Data)
})
t.Run("cannot update informer value", func(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
cm1, err := settingsManager.GetConfigMapByName(common.ArgoCDConfigMapName)
require.NoError(t, err)
cm1.Data["test"] = "invalid"
@@ -85,13 +85,13 @@ func TestGetConfigMapByName(t *testing.T) {
func TestGetSecretByName(t *testing.T) {
t.Run("data is never nil", func(t *testing.T) {
_, settingsManager := fixtures(nil, func(secret *corev1.Secret) { secret.Data = nil })
_, settingsManager := fixtures(t.Context(), nil, func(secret *corev1.Secret) { secret.Data = nil })
secret, err := settingsManager.GetSecretByName(common.ArgoCDSecretName)
require.NoError(t, err)
assert.NotNil(t, secret.Data)
})
t.Run("cannot update informer value", func(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
s1, err := settingsManager.GetSecretByName(common.ArgoCDSecretName)
require.NoError(t, err)
s1.Data["test"] = []byte("invalid")
@@ -152,7 +152,7 @@ func TestGetResourceFilter(t *testing.T) {
"resource.exclusions": "\n - apiGroups: [\"group1\"]\n kinds: [\"kind1\"]\n clusters: [\"cluster1\"]\n",
"resource.inclusions": "\n - apiGroups: [\"group2\"]\n kinds: [\"kind2\"]\n clusters: [\"cluster2\"]\n",
}
_, settingsManager := fixtures(data)
_, settingsManager := fixtures(t.Context(), data)
filter, err := settingsManager.GetResourcesFilter()
require.NoError(t, err)
assert.Equal(t, &ResourcesFilter{
@@ -162,14 +162,14 @@ func TestGetResourceFilter(t *testing.T) {
}
func TestInClusterServerAddressEnabled(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"cluster.inClusterEnabled": "true",
})
argoCDCM, err := settingsManager.getConfigMap()
require.NoError(t, err)
assert.Equal(t, "true", argoCDCM.Data[inClusterEnabledKey])
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"cluster.inClusterEnabled": "false",
})
argoCDCM, err = settingsManager.getConfigMap()
@@ -211,7 +211,7 @@ func TestInClusterServerAddressEnabledByDefault(t *testing.T) {
func TestGetAppInstanceLabelKey(t *testing.T) {
t.Run("should get custom instanceLabelKey", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.instanceLabelKey": "testLabel",
})
label, err := settingsManager.GetAppInstanceLabelKey()
@@ -220,7 +220,7 @@ func TestGetAppInstanceLabelKey(t *testing.T) {
})
t.Run("should get default instanceLabelKey if custom not defined", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
label, err := settingsManager.GetAppInstanceLabelKey()
require.NoError(t, err)
assert.Equal(t, common.LabelKeyAppInstance, label)
@@ -229,7 +229,7 @@ func TestGetAppInstanceLabelKey(t *testing.T) {
func TestGetTrackingMethod(t *testing.T) {
t.Run("should get custom trackingMethod", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.resourceTrackingMethod": string(v1alpha1.TrackingMethodLabel),
})
label, err := settingsManager.GetTrackingMethod()
@@ -238,7 +238,7 @@ func TestGetTrackingMethod(t *testing.T) {
})
t.Run("should get default trackingMethod if custom not defined", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
label, err := settingsManager.GetTrackingMethod()
require.NoError(t, err)
assert.Equal(t, string(v1alpha1.TrackingMethodAnnotation), label)
@@ -246,7 +246,7 @@ func TestGetTrackingMethod(t *testing.T) {
}
func TestGetInstallationID(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"installationID": "123456789",
})
id, err := settingsManager.GetInstallationID()
@@ -255,14 +255,14 @@ func TestGetInstallationID(t *testing.T) {
}
func TestApplicationFineGrainedRBACInheritanceDisabledDefault(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
flag, err := settingsManager.ApplicationFineGrainedRBACInheritanceDisabled()
require.NoError(t, err)
assert.True(t, flag)
}
func TestApplicationFineGrainedRBACInheritanceDisabled(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"server.rbac.disableApplicationFineGrainedRBACInheritance": "false",
})
flag, err := settingsManager.ApplicationFineGrainedRBACInheritanceDisabled()
@@ -271,12 +271,12 @@ func TestApplicationFineGrainedRBACInheritanceDisabled(t *testing.T) {
}
func TestGetIsIgnoreResourceUpdatesEnabled(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
ignoreResourceUpdatesEnabled, err := settingsManager.GetIsIgnoreResourceUpdatesEnabled()
require.NoError(t, err)
assert.True(t, ignoreResourceUpdatesEnabled)
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.ignoreResourceUpdatesEnabled": "true",
})
ignoreResourceUpdatesEnabled, err = settingsManager.GetIsIgnoreResourceUpdatesEnabled()
@@ -285,7 +285,7 @@ func TestGetIsIgnoreResourceUpdatesEnabled(t *testing.T) {
}
func TestGetIsIgnoreResourceUpdatesEnabledFalse(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.ignoreResourceUpdatesEnabled": "false",
})
ignoreResourceUpdatesEnabled, err := settingsManager.GetIsIgnoreResourceUpdatesEnabled()
@@ -299,7 +299,7 @@ func TestGetResourceOverrides(t *testing.T) {
}}
crdGK := "apiextensions.k8s.io/CustomResourceDefinition"
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.customizations": `
admissionregistration.k8s.io/MutatingWebhookConfiguration:
ignoreDifferences: |
@@ -336,7 +336,7 @@ func TestGetResourceOverrides(t *testing.T) {
assert.Equal(t, ignoreStatus, globalOverrides)
// with value all, status of all objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: all`,
})
@@ -348,7 +348,7 @@ func TestGetResourceOverrides(t *testing.T) {
assert.Equal(t, ignoreStatus, globalOverrides)
// with value crd, status of crd objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: crd`,
@@ -371,7 +371,7 @@ func TestGetResourceOverrides(t *testing.T) {
}}, crdOverrides)
// with incorrect value, status of all objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: foobar`,
})
@@ -383,7 +383,7 @@ func TestGetResourceOverrides(t *testing.T) {
assert.Equal(t, ignoreStatus, globalOverrides)
// with value non-string off, status of no objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: off`,
})
@@ -392,7 +392,7 @@ func TestGetResourceOverrides(t *testing.T) {
assert.Empty(t, overrides)
// with value non-string false, status of no objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: false`,
})
@@ -401,7 +401,7 @@ func TestGetResourceOverrides(t *testing.T) {
assert.Empty(t, overrides)
// with value none, status of no objects should be ignored
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: none`,
})
@@ -419,7 +419,7 @@ func TestGetResourceOverridesHealthWithWildcard(t *testing.T) {
}
t.Run("TestResourceHealthOverrideWithWildcard", func(t *testing.T) {
_, settingsManager := fixtures(data)
_, settingsManager := fixtures(t.Context(), data)
overrides, err := settingsManager.GetResourceOverrides()
require.NoError(t, err)
@@ -429,7 +429,7 @@ func TestGetResourceOverridesHealthWithWildcard(t *testing.T) {
}
func TestSettingsManager_GetResourceOverrides_with_empty_string(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
resourceCustomizationsKey: "",
})
overrides, err := settingsManager.GetResourceOverrides()
@@ -463,7 +463,7 @@ func TestGetResourceOverrides_with_splitted_keys(t *testing.T) {
}
t.Run("MergedKey", func(t *testing.T) {
_, settingsManager := fixtures(data)
_, settingsManager := fixtures(t.Context(), data)
overrides, err := settingsManager.GetResourceOverrides()
require.NoError(t, err)
@@ -512,7 +512,7 @@ func TestGetResourceOverrides_with_splitted_keys(t *testing.T) {
- bar`,
}
_, settingsManager := fixtures(mergemaps(data, newData))
_, settingsManager := fixtures(t.Context(), mergemaps(data, newData))
overrides, err := settingsManager.GetResourceOverrides()
require.NoError(t, err)
@@ -576,7 +576,7 @@ func TestGetIgnoreResourceUpdatesOverrides(t *testing.T) {
- .webhooks[1].clientConfig.caBundle`,
}
_, settingsManager := fixtures(testCustomizations)
_, settingsManager := fixtures(t.Context(), testCustomizations)
overrides, err := settingsManager.GetIgnoreResourceUpdatesOverrides()
require.NoError(t, err)
@@ -596,7 +596,7 @@ func TestGetIgnoreResourceUpdatesOverrides(t *testing.T) {
}, overrides["admissionregistration.k8s.io/MutatingWebhookConfiguration"])
// without ignoreDifferencesOnResourceUpdates, only ignoreResourceUpdates should be added
_, settingsManager = fixtures(mergemaps(map[string]string{
_, settingsManager = fixtures(t.Context(), mergemaps(map[string]string{
"resource.compareoptions": `
ignoreResourceStatusField: none
ignoreDifferencesOnResourceUpdates: false`,
@@ -632,7 +632,7 @@ func TestConvertToOverrideKey(t *testing.T) {
func TestGetResourceCompareOptions(t *testing.T) {
// ignoreAggregatedRules is true
{
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.compareoptions": "ignoreAggregatedRoles: true",
})
compareOptions, err := settingsManager.GetResourceCompareOptions()
@@ -642,7 +642,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
// ignoreAggregatedRules is false
{
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.compareoptions": "ignoreAggregatedRoles: false",
})
compareOptions, err := settingsManager.GetResourceCompareOptions()
@@ -652,7 +652,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
// ignoreDifferencesOnResourceUpdates is true
{
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.compareoptions": "ignoreDifferencesOnResourceUpdates: true",
})
compareOptions, err := settingsManager.GetResourceCompareOptions()
@@ -662,7 +662,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
// ignoreDifferencesOnResourceUpdates is false
{
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.compareoptions": "ignoreDifferencesOnResourceUpdates: false",
})
compareOptions, err := settingsManager.GetResourceCompareOptions()
@@ -672,7 +672,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
// The empty resource.compareoptions should result in default being returned
{
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.compareoptions": "",
})
compareOptions, err := settingsManager.GetResourceCompareOptions()
@@ -684,7 +684,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
// resource.compareoptions not defined - should result in default being returned
{
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
compareOptions, err := settingsManager.GetResourceCompareOptions()
defaultOptions := GetDefaultDiffOptions()
require.NoError(t, err)
@@ -695,7 +695,7 @@ func TestGetResourceCompareOptions(t *testing.T) {
func TestSettingsManager_GetKustomizeBuildOptions(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
settings, err := settingsManager.GetKustomizeSettings()
@@ -704,7 +704,7 @@ func TestSettingsManager_GetKustomizeBuildOptions(t *testing.T) {
assert.Empty(t, settings.Versions)
})
t.Run("Set", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"kustomize.buildOptions": "foo",
"kustomize.version.v3.2.1": "somePath",
})
@@ -717,7 +717,7 @@ func TestSettingsManager_GetKustomizeBuildOptions(t *testing.T) {
})
t.Run("Kustomize settings per-version", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"kustomize.buildOptions": "--global true",
"kustomize.version.v3.2.1": "/path_3.2.1",
"kustomize.buildOptions.v3.2.3": "--options v3.2.3",
@@ -750,7 +750,7 @@ func TestSettingsManager_GetKustomizeBuildOptions(t *testing.T) {
})
t.Run("Kustomize settings per-version with duplicate versions", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"kustomize.buildOptions": "--global true",
"kustomize.version.v3.2.1": "/path_3.2.1",
"kustomize.buildOptions.v3.2.1": "--options v3.2.3",
@@ -764,7 +764,7 @@ func TestSettingsManager_GetKustomizeBuildOptions(t *testing.T) {
})
t.Run("Config map with no Kustomize settings", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"other.options": "--global true",
})
@@ -792,9 +792,9 @@ func TestSettingsManager_GetEventLabelKeys(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
if tt.data != "" {
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
resourceIncludeEventLabelKeys: tt.data,
resourceExcludeEventLabelKeys: tt.data,
})
@@ -865,7 +865,7 @@ func Test_GetKustomizeBinaryPath(t *testing.T) {
}
func TestGetGoogleAnalytics(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"ga.trackingid": "123",
})
ga, err := settingsManager.GetGoogleAnalytics()
@@ -876,14 +876,14 @@ func TestGetGoogleAnalytics(t *testing.T) {
func TestSettingsManager_GetHelp(t *testing.T) {
t.Run("Default", func(t *testing.T) {
_, settingsManager := fixtures(nil)
_, settingsManager := fixtures(t.Context(), nil)
h, err := settingsManager.GetHelp()
require.NoError(t, err)
assert.Empty(t, h.ChatURL)
assert.Empty(t, h.ChatText)
})
t.Run("Set", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"help.chatUrl": "foo",
"help.chatText": "bar",
})
@@ -893,7 +893,7 @@ func TestSettingsManager_GetHelp(t *testing.T) {
assert.Equal(t, "bar", h.ChatText)
})
t.Run("SetOnlyChatUrl", func(t *testing.T) {
_, settingManager := fixtures(map[string]string{
_, settingManager := fixtures(t.Context(), map[string]string{
"help.chatUrl": "foo",
})
h, err := settingManager.GetHelp()
@@ -902,7 +902,7 @@ func TestSettingsManager_GetHelp(t *testing.T) {
assert.Equal(t, "Chat now!", h.ChatText)
})
t.Run("SetOnlyChatText", func(t *testing.T) {
_, settingManager := fixtures(map[string]string{
_, settingManager := fixtures(t.Context(), map[string]string{
"help.chatText": "bar",
})
h, err := settingManager.GetHelp()
@@ -911,7 +911,7 @@ func TestSettingsManager_GetHelp(t *testing.T) {
assert.Empty(t, h.ChatText)
})
t.Run("GetBinaryUrls", func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"help.download.darwin-amd64": "amd64-path",
"help.download.linux-s390x": "s390x-path",
"help.download.unsupported": "nowhere",
@@ -1318,7 +1318,7 @@ func Test_GetTLSConfiguration(t *testing.T) {
kubeClient := fake.NewClientset(cm, secret, tlsSecret)
callCount := 0
settingsManager := NewSettingsManager(context.Background(), kubeClient, "default", func(mgr *SettingsManager) {
settingsManager := NewSettingsManager(t.Context(), kubeClient, "default", func(mgr *SettingsManager) {
mgr.tlsCertParser = func(certpem []byte, keypem []byte) (tls.Certificate, error) {
callCount++
@@ -1376,7 +1376,7 @@ func Test_GetTLSConfiguration(t *testing.T) {
kubeClient := fake.NewClientset(cm, secret, tlsSecret)
callCount := 0
settingsManager := NewSettingsManager(context.Background(), kubeClient, "default", func(mgr *SettingsManager) {
settingsManager := NewSettingsManager(t.Context(), kubeClient, "default", func(mgr *SettingsManager) {
mgr.tlsCertParser = func(certpem []byte, keypem []byte) (tls.Certificate, error) {
callCount++
@@ -1566,21 +1566,21 @@ func Test_GetTLSConfiguration(t *testing.T) {
}
func TestDownloadArgoCDBinaryUrls(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"help.download.darwin-amd64": "some-url",
})
argoCDCM, err := settingsManager.getConfigMap()
require.NoError(t, err)
assert.Equal(t, "some-url", argoCDCM.Data["help.download.darwin-amd64"])
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"help.download.linux-s390x": "some-url",
})
argoCDCM, err = settingsManager.getConfigMap()
require.NoError(t, err)
assert.Equal(t, "some-url", argoCDCM.Data["help.download.linux-s390x"])
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"help.download.unsupported": "some-url",
})
argoCDCM, err = settingsManager.getConfigMap()
@@ -2087,7 +2087,7 @@ func TestIsImpersonationEnabled(t *testing.T) {
// When there is no impersonation feature flag present in the argocd-cm,
// Then IsImpersonationEnabled() must return false (default value) and nil error.
_, settingsManager = fixtures(map[string]string{})
_, settingsManager = fixtures(t.Context(), map[string]string{})
featureFlag, err = settingsManager.IsImpersonationEnabled()
require.False(t, featureFlag,
"with empty argocd-cm config map, IsImpersonationEnabled() must return false (default value)")
@@ -2096,7 +2096,7 @@ func TestIsImpersonationEnabled(t *testing.T) {
// When user disables the feature explicitly,
// Then IsImpersonationEnabled() must return false and nil error.
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"application.sync.impersonation.enabled": "false",
})
featureFlag, err = settingsManager.IsImpersonationEnabled()
@@ -2107,7 +2107,7 @@ func TestIsImpersonationEnabled(t *testing.T) {
// When user enables the feature explicitly,
// Then IsImpersonationEnabled() must return true and nil error.
_, settingsManager = fixtures(map[string]string{
_, settingsManager = fixtures(t.Context(), map[string]string{
"application.sync.impersonation.enabled": "true",
})
featureFlag, err = settingsManager.IsImpersonationEnabled()
@@ -2132,7 +2132,7 @@ func TestRequireOverridePrivilegeForRevisionSyncNoConfigMap(t *testing.T) {
func TestRequireOverridePrivilegeForRevisionSyncEmptyConfigMap(t *testing.T) {
// When there is no feature flag present in the argocd-cm,
// Then RequireOverridePrivilegeForRevisionSync() must return false (default value) and nil error.
_, settingsManager := fixtures(map[string]string{})
_, settingsManager := fixtures(t.Context(), map[string]string{})
featureFlag, err := settingsManager.RequireOverridePrivilegeForRevisionSync()
require.False(t, featureFlag,
"with empty argocd-cm config map, RequireOverridePrivilegeForRevisionSync() must return false (default value)")
@@ -2143,7 +2143,7 @@ func TestRequireOverridePrivilegeForRevisionSyncEmptyConfigMap(t *testing.T) {
func TestRequireOverridePrivilegeForRevisionSyncFalse(t *testing.T) {
// When user disables the feature explicitly,
// Then RequireOverridePrivilegeForRevisionSync() must return false and nil error.
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.sync.RequireOverridePrivilegeForRevisionSync": "false",
})
featureFlag, err := settingsManager.RequireOverridePrivilegeForRevisionSync()
@@ -2156,7 +2156,7 @@ func TestRequireOverridePrivilegeForRevisionSyncFalse(t *testing.T) {
func TestRequireOverridePrivilegeForRevisionSyncTrue(t *testing.T) {
// When user enables the feature explicitly,
// Then RequireOverridePrivilegeForRevisionSync() must return true and nil error.
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.sync.requireOverridePrivilegeForRevisionSync": "true",
})
featureFlag, err := settingsManager.RequireOverridePrivilegeForRevisionSync()
@@ -2169,7 +2169,7 @@ func TestRequireOverridePrivilegeForRevisionSyncTrue(t *testing.T) {
func TestRequireOverridePrivilegeForRevisionSyncParseError(t *testing.T) {
// When a value is set that cannot be parsed as boolean,
// Then RequireOverridePrivilegeForRevisionSync() must return false and nil error.
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
"application.sync.requireOverridePrivilegeForRevisionSync": "BANANA",
})
featureFlag, err := settingsManager.RequireOverridePrivilegeForRevisionSync()
@@ -2203,7 +2203,7 @@ func TestSettingsManager_GetHideSecretAnnotations(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
resourceSensitiveAnnotationsKey: tt.input,
})
keys := settingsManager.GetSensitiveAnnotations()
@@ -2242,7 +2242,7 @@ func TestSettingsManager_GetAllowedNodeLabels(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
_, settingsManager := fixtures(t.Context(), map[string]string{
allowedNodeLabelsKey: tt.input,
})
keys := settingsManager.GetAllowedNodeLabels()