mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
chore: upgrade Go to 1.24 (#22242)
Signed-off-by: sivchari <shibuuuu5@gmail.com>
This commit is contained in:
parent
bd1018af5e
commit
922d080ae5
118 changed files with 1412 additions and 1479 deletions
2
.github/workflows/ci-build.yaml
vendored
2
.github/workflows/ci-build.yaml
vendored
|
|
@ -14,7 +14,7 @@ on:
|
|||
env:
|
||||
# Golang version to use across CI steps
|
||||
# renovate: datasource=golang-version packageName=golang
|
||||
GOLANG_VERSION: '1.23.5'
|
||||
GOLANG_VERSION: '1.24.1'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
|
|
|||
4
.github/workflows/image.yaml
vendored
4
.github/workflows/image.yaml
vendored
|
|
@ -53,7 +53,7 @@ jobs:
|
|||
with:
|
||||
# Note: cannot use env variables to set go-version (https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations)
|
||||
# renovate: datasource=golang-version packageName=golang
|
||||
go-version: 1.23.5
|
||||
go-version: 1.24.1
|
||||
platforms: ${{ needs.set-vars.outputs.platforms }}
|
||||
push: false
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ jobs:
|
|||
ghcr_image_name: ghcr.io/argoproj/argo-cd/argocd:${{ needs.set-vars.outputs.image-tag }}
|
||||
# Note: cannot use env variables to set go-version (https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations)
|
||||
# renovate: datasource=golang-version packageName=golang
|
||||
go-version: 1.23.5
|
||||
go-version: 1.24.1
|
||||
platforms: ${{ needs.set-vars.outputs.platforms }}
|
||||
push: true
|
||||
secrets:
|
||||
|
|
|
|||
4
.github/workflows/release.yaml
vendored
4
.github/workflows/release.yaml
vendored
|
|
@ -11,7 +11,7 @@ permissions: {}
|
|||
|
||||
env:
|
||||
# renovate: datasource=golang-version packageName=golang
|
||||
GOLANG_VERSION: '1.23.5' # Note: go-version must also be set in job argocd-image.with.go-version
|
||||
GOLANG_VERSION: '1.24.1' # Note: go-version must also be set in job argocd-image.with.go-version
|
||||
|
||||
jobs:
|
||||
argocd-image:
|
||||
|
|
@ -25,7 +25,7 @@ jobs:
|
|||
quay_image_name: quay.io/argoproj/argocd:${{ github.ref_name }}
|
||||
# Note: cannot use env variables to set go-version (https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations)
|
||||
# renovate: datasource=golang-version packageName=golang
|
||||
go-version: 1.23.5
|
||||
go-version: 1.24.1
|
||||
platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le
|
||||
push: true
|
||||
secrets:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ ARG BASE_IMAGE=docker.io/library/ubuntu:24.04@sha256:80dd3c3b9c6cecb9f1667e9290b
|
|||
# Initial stage which pulls prepares build dependencies and CLI tooling we need for our final image
|
||||
# Also used as the image in CI jobs so needs all dependencies
|
||||
####################################################################################################
|
||||
FROM docker.io/library/golang:1.23.5@sha256:8c10f21bec412f08f73aa7b97ca5ac5f28a39d8a88030ad8a339fd0a781d72b4 AS builder
|
||||
FROM docker.io/library/golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418 AS builder
|
||||
|
||||
RUN echo 'deb http://archive.debian.org/debian buster-backports main' >> /etc/apt/sources.list
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ RUN HOST_ARCH=$TARGETARCH NODE_ENV='production' NODE_ONLINE_ENV='online' NODE_OP
|
|||
####################################################################################################
|
||||
# Argo CD Build stage which performs the actual build of Argo CD binaries
|
||||
####################################################################################################
|
||||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.23.5@sha256:8c10f21bec412f08f73aa7b97ca5ac5f28a39d8a88030ad8a339fd0a781d72b4 AS argocd-build
|
||||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418 AS argocd-build
|
||||
|
||||
WORKDIR /go/src/github.com/argoproj/argo-cd
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -1097,12 +1096,12 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err = r.createOrUpdateInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps)
|
||||
err = r.createOrUpdateInCluster(t.Context(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, obj := range c.expected {
|
||||
got := &v1alpha1.Application{}
|
||||
_ = client.Get(context.Background(), crtclient.ObjectKey{
|
||||
_ = client.Get(t.Context(), crtclient.ObjectKey{
|
||||
Namespace: obj.Namespace,
|
||||
Name: obj.Name,
|
||||
}, got)
|
||||
|
|
@ -1198,7 +1197,7 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) {
|
|||
kubeclientset := kubefake.NewSimpleClientset(objects...)
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -1208,18 +1207,18 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
ArgoDB: argodb,
|
||||
}
|
||||
clusterList, err := utils.ListClusters(context.Background(), kubeclientset, "namespace")
|
||||
clusterList, err := utils.ListClusters(t.Context(), kubeclientset, "namespace")
|
||||
require.NoError(t, err)
|
||||
|
||||
appLog := log.WithFields(log.Fields{"app": app.Name, "appSet": ""})
|
||||
|
||||
appInputParam := app.DeepCopy()
|
||||
|
||||
err = r.removeFinalizerOnInvalidDestination(context.Background(), appSet, appInputParam, clusterList, appLog)
|
||||
err = r.removeFinalizerOnInvalidDestination(t.Context(), appSet, appInputParam, clusterList, appLog)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedApp := v1alpha1.Application{}
|
||||
err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
err = client.Get(t.Context(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
require.NoError(t, err)
|
||||
|
||||
// App on the cluster should have the expected finalizers
|
||||
|
|
@ -1353,7 +1352,7 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) {
|
|||
kubeclientset := getDefaultTestClientSet(secret)
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -1364,18 +1363,18 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) {
|
|||
ArgoDB: argodb,
|
||||
}
|
||||
|
||||
clusterList, err := utils.ListClusters(context.Background(), kubeclientset, "argocd")
|
||||
clusterList, err := utils.ListClusters(t.Context(), kubeclientset, "argocd")
|
||||
require.NoError(t, err)
|
||||
|
||||
appLog := log.WithFields(log.Fields{"app": app.Name, "appSet": ""})
|
||||
|
||||
appInputParam := app.DeepCopy()
|
||||
|
||||
err = r.removeFinalizerOnInvalidDestination(context.Background(), appSet, appInputParam, clusterList, appLog)
|
||||
err = r.removeFinalizerOnInvalidDestination(t.Context(), appSet, appInputParam, clusterList, appLog)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedApp := v1alpha1.Application{}
|
||||
err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
err = client.Get(t.Context(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
require.NoError(t, err)
|
||||
|
||||
finalizerRemoved := len(retrievedApp.Finalizers) == 0
|
||||
|
|
@ -1448,11 +1447,11 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err = r.removeOwnerReferencesOnDeleteAppSet(context.Background(), appSet)
|
||||
err = r.removeOwnerReferencesOnDeleteAppSet(t.Context(), appSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedApp := v1alpha1.Application{}
|
||||
err = client.Get(context.Background(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
err = client.Get(t.Context(), crtclient.ObjectKeyFromObject(&app), &retrievedApp)
|
||||
require.NoError(t, err)
|
||||
|
||||
ownerReferencesRemoved := len(retrievedApp.OwnerReferences) == 0
|
||||
|
|
@ -1646,12 +1645,12 @@ func TestCreateApplications(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err = r.createInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.apps)
|
||||
err = r.createInCluster(t.Context(), log.NewEntry(log.StandardLogger()), c.appSet, c.apps)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, obj := range c.expected {
|
||||
got := &v1alpha1.Application{}
|
||||
_ = client.Get(context.Background(), crtclient.ObjectKey{
|
||||
_ = client.Get(t.Context(), crtclient.ObjectKey{
|
||||
Namespace: obj.Namespace,
|
||||
Name: obj.Name,
|
||||
}, got)
|
||||
|
|
@ -1789,13 +1788,13 @@ func TestDeleteInCluster(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err = r.deleteInCluster(context.TODO(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps)
|
||||
err = r.deleteInCluster(t.Context(), log.NewEntry(log.StandardLogger()), c.appSet, c.desiredApps)
|
||||
require.NoError(t, err)
|
||||
|
||||
// For each of the expected objects, verify they exist on the cluster
|
||||
for _, obj := range c.expected {
|
||||
got := &v1alpha1.Application{}
|
||||
_ = client.Get(context.Background(), crtclient.ObjectKey{
|
||||
_ = client.Get(t.Context(), crtclient.ObjectKey{
|
||||
Namespace: obj.Namespace,
|
||||
Name: obj.Name,
|
||||
}, got)
|
||||
|
|
@ -1809,7 +1808,7 @@ func TestDeleteInCluster(t *testing.T) {
|
|||
// Verify each of the unexpected objs cannot be found
|
||||
for _, obj := range c.notExpected {
|
||||
got := &v1alpha1.Application{}
|
||||
err := client.Get(context.Background(), crtclient.ObjectKey{
|
||||
err := client.Get(t.Context(), crtclient.ObjectKey{
|
||||
Namespace: obj.Namespace,
|
||||
Name: obj.Name,
|
||||
}, got)
|
||||
|
|
@ -1915,7 +1914,7 @@ func TestRequeueGeneratorFails(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
res, err := r.Reconcile(context.Background(), req)
|
||||
res, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ReconcileRequeueOnValidationError, res.RequeueAfter)
|
||||
}
|
||||
|
|
@ -2088,7 +2087,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
|
|||
|
||||
kubeclientset := getDefaultTestClientSet(secret)
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2102,7 +2101,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
|
|||
}
|
||||
|
||||
appSetInfo := v1alpha1.ApplicationSet{}
|
||||
validationErrors, _ := r.validateGeneratedApplications(context.TODO(), cc.apps, appSetInfo)
|
||||
validationErrors, _ := r.validateGeneratedApplications(t.Context(), cc.apps, appSetInfo)
|
||||
assert.Equal(t, cc.validationErrors, validationErrors)
|
||||
})
|
||||
}
|
||||
|
|
@ -2153,7 +2152,7 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &project).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2178,19 +2177,19 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify that on validation error, no error is returned, but the object is requeued
|
||||
res, err := r.Reconcile(context.Background(), req)
|
||||
res, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ReconcileRequeueOnValidationError, res.RequeueAfter)
|
||||
|
||||
var app v1alpha1.Application
|
||||
|
||||
// make sure good app got created
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-project"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-project"}, &app)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "good-project", app.Name)
|
||||
|
||||
// make sure bad app was not created
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "bad-project"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "bad-project"}, &app)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -2352,7 +2351,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testCase.appset).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).WithStatusSubresource(&testCase.appset).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2368,7 +2367,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, condition := range testCase.conditions {
|
||||
err = r.setApplicationSetStatusCondition(context.TODO(), &testCase.appset, condition, true)
|
||||
err = r.setApplicationSetStatusCondition(t.Context(), &testCase.appset, condition, true)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -2440,7 +2439,7 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2466,20 +2465,20 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
}
|
||||
|
||||
// Verify that on validation error, no error is returned, but the object is requeued
|
||||
resCreate, err := r.Reconcile(context.Background(), req)
|
||||
resCreate, err := r.Reconcile(t.Context(), req)
|
||||
require.NoErrorf(t, err, "Reconcile failed with error: %v", err)
|
||||
assert.Equal(t, time.Duration(0), resCreate.RequeueAfter)
|
||||
|
||||
var app v1alpha1.Application
|
||||
|
||||
// make sure good app got created
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "good-cluster", app.Name)
|
||||
|
||||
// Update resource
|
||||
var retrievedApplicationSet v1alpha1.ApplicationSet
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
retrievedApplicationSet.Spec.Template.Annotations = map[string]string{"annotation-key": "annotation-value"}
|
||||
|
|
@ -2489,13 +2488,13 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
Values: "global.test: test",
|
||||
}
|
||||
|
||||
err = r.Client.Update(context.TODO(), &retrievedApplicationSet)
|
||||
err = r.Client.Update(t.Context(), &retrievedApplicationSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
resUpdate, err := r.Reconcile(context.Background(), req)
|
||||
resUpdate, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), resUpdate.RequeueAfter)
|
||||
assert.Equal(t, "good-cluster", app.Name)
|
||||
|
|
@ -2615,7 +2614,7 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2641,20 +2640,20 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
}
|
||||
|
||||
// Verify that on validation error, no error is returned, but the object is requeued
|
||||
resCreate, err := r.Reconcile(context.Background(), req)
|
||||
resCreate, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), resCreate.RequeueAfter)
|
||||
|
||||
var app v1alpha1.Application
|
||||
|
||||
// make sure good app got created
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "good-cluster"}, &app)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "good-cluster", app.Name)
|
||||
|
||||
// Update resource
|
||||
var retrievedApplicationSet v1alpha1.ApplicationSet
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &retrievedApplicationSet)
|
||||
require.NoError(t, err)
|
||||
retrievedApplicationSet.Spec.Generators = []v1alpha1.ApplicationSetGenerator{
|
||||
{
|
||||
|
|
@ -2664,15 +2663,15 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
|
|||
},
|
||||
}
|
||||
|
||||
err = r.Client.Update(context.TODO(), &retrievedApplicationSet)
|
||||
err = r.Client.Update(t.Context(), &retrievedApplicationSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
resUpdate, err := r.Reconcile(context.Background(), req)
|
||||
resUpdate, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var apps v1alpha1.ApplicationList
|
||||
|
||||
err = r.Client.List(context.TODO(), &apps)
|
||||
err = r.Client.List(t.Context(), &apps)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), resUpdate.RequeueAfter)
|
||||
|
||||
|
|
@ -2804,7 +2803,7 @@ func TestPolicies(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2829,25 +2828,25 @@ func TestPolicies(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check if Application is created
|
||||
res, err := r.Reconcile(context.Background(), req)
|
||||
res, err := r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), res.RequeueAfter)
|
||||
|
||||
var app v1alpha1.Application
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "value", app.Annotations["key"])
|
||||
|
||||
// Check if Application is updated
|
||||
app.Annotations["key"] = "edited"
|
||||
err = r.Client.Update(context.TODO(), &app)
|
||||
err = r.Client.Update(t.Context(), &app)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err = r.Reconcile(context.Background(), req)
|
||||
res, err = r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), res.RequeueAfter)
|
||||
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
require.NoError(t, err)
|
||||
|
||||
if c.allowedUpdate {
|
||||
|
|
@ -2857,21 +2856,21 @@ func TestPolicies(t *testing.T) {
|
|||
}
|
||||
|
||||
// Check if Application is deleted
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &appSet)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "name"}, &appSet)
|
||||
require.NoError(t, err)
|
||||
appSet.Spec.Generators[0] = v1alpha1.ApplicationSetGenerator{
|
||||
List: &v1alpha1.ListGenerator{
|
||||
Elements: []apiextensionsv1.JSON{},
|
||||
},
|
||||
}
|
||||
err = r.Client.Update(context.TODO(), &appSet)
|
||||
err = r.Client.Update(t.Context(), &appSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err = r.Reconcile(context.Background(), req)
|
||||
res, err = r.Reconcile(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Duration(0), res.RequeueAfter)
|
||||
|
||||
err = r.Client.Get(context.TODO(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
err = r.Client.Get(t.Context(), crtclient.ObjectKey{Namespace: "argocd", Name: "my-app"}, &app)
|
||||
require.NoError(t, err)
|
||||
if c.allowedDelete {
|
||||
assert.NotNil(t, app.DeletionTimestamp)
|
||||
|
|
@ -2963,7 +2962,7 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -2978,7 +2977,7 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err = r.setAppSetApplicationStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appStatuses)
|
||||
err = r.setAppSetApplicationStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appStatuses)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, cc.expectedAppStatuses, cc.appSet.Status.ApplicationStatus)
|
||||
|
|
@ -3723,7 +3722,7 @@ func TestBuildAppDependencyList(t *testing.T) {
|
|||
t.Run(cc.name, func(t *testing.T) {
|
||||
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -4391,7 +4390,7 @@ func TestBuildAppSyncMap(t *testing.T) {
|
|||
t.Run(cc.name, func(t *testing.T) {
|
||||
kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -5336,7 +5335,7 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -5348,7 +5347,7 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
appStatuses, err := r.updateApplicationSetApplicationStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps, cc.appStepMap)
|
||||
appStatuses, err := r.updateApplicationSetApplicationStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps, cc.appStepMap)
|
||||
|
||||
// opt out of testing the LastTransitionTime is accurate
|
||||
for i := range appStatuses {
|
||||
|
|
@ -6086,7 +6085,7 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&cc.appSet).WithStatusSubresource(&cc.appSet).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -6098,7 +6097,7 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
appStatuses, err := r.updateApplicationSetApplicationStatusProgress(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appSyncMap, cc.appStepMap)
|
||||
appStatuses, err := r.updateApplicationSetApplicationStatusProgress(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.appSyncMap, cc.appStepMap)
|
||||
|
||||
// opt out of testing the LastTransitionTime is accurate
|
||||
for i := range appStatuses {
|
||||
|
|
@ -6298,7 +6297,7 @@ func TestUpdateResourceStatus(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(&cc.appSet).WithObjects(&cc.appSet).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -6310,7 +6309,7 @@ func TestUpdateResourceStatus(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
err := r.updateResourcesStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
|
||||
require.NoError(t, err, "expected no errors, but errors occurred")
|
||||
assert.Equal(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual")
|
||||
|
|
@ -6389,7 +6388,7 @@ func TestResourceStatusAreOrdered(t *testing.T) {
|
|||
client := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(&cc.appSet).WithObjects(&cc.appSet).Build()
|
||||
metrics := appsetmetrics.NewFakeAppsetMetrics()
|
||||
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
|
||||
argodb := db.NewDB("argocd", settings.NewSettingsManager(t.Context(), kubeclientset, "argocd"), kubeclientset)
|
||||
|
||||
r := ApplicationSetReconciler{
|
||||
Client: client,
|
||||
|
|
@ -6401,13 +6400,13 @@ func TestResourceStatusAreOrdered(t *testing.T) {
|
|||
Metrics: metrics,
|
||||
}
|
||||
|
||||
err := r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
err := r.updateResourcesStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
require.NoError(t, err, "expected no errors, but errors occurred")
|
||||
|
||||
err = r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
err = r.updateResourcesStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
require.NoError(t, err, "expected no errors, but errors occurred")
|
||||
|
||||
err = r.updateResourcesStatus(context.TODO(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
err = r.updateResourcesStatus(t.Context(), log.NewEntry(log.StandardLogger()), &cc.appSet, cc.apps)
|
||||
require.NoError(t, err, "expected no errors, but errors occurred")
|
||||
|
||||
assert.Equal(t, cc.expectedResources, cc.appSet.Status.Resources, "expected resources did not match actual")
|
||||
|
|
@ -6671,7 +6670,7 @@ func TestMigrateStatus(t *testing.T) {
|
|||
Client: client,
|
||||
}
|
||||
|
||||
err := r.migrateStatus(context.Background(), &tc.appset)
|
||||
err := r.migrateStatus(t.Context(), &tc.appset)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedStatus, tc.appset.Status)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
argocommon "github.com/argoproj/argo-cd/v3/common"
|
||||
|
|
@ -550,7 +549,7 @@ func TestClusterEventHandler(t *testing.T) {
|
|||
|
||||
mockAddRateLimitingInterface := mockAddRateLimitingInterface{}
|
||||
|
||||
handler.queueRelatedAppGenerators(context.Background(), &mockAddRateLimitingInterface, &test.secret)
|
||||
handler.queueRelatedAppGenerators(t.Context(), &mockAddRateLimitingInterface, &test.secret)
|
||||
|
||||
assert.ElementsMatch(t, mockAddRateLimitingInterface.addedItems, test.expectedRequests)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ import (
|
|||
|
||||
func TestRequeueAfter(t *testing.T) {
|
||||
mockServer := &mocks.Repos{}
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
scheme := runtime.NewScheme()
|
||||
err := argov1alpha1.AddToScheme(scheme)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ func TestGenerateParams(t *testing.T) {
|
|||
testCase.clientError,
|
||||
}
|
||||
|
||||
clusterGenerator := NewClusterGenerator(context.Background(), cl, appClientset, "namespace")
|
||||
clusterGenerator := NewClusterGenerator(t.Context(), cl, appClientset, "namespace")
|
||||
|
||||
applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -853,7 +853,7 @@ func TestGenerateParamsGoTemplate(t *testing.T) {
|
|||
testCase.clientError,
|
||||
}
|
||||
|
||||
clusterGenerator := NewClusterGenerator(context.Background(), cl, appClientset, "namespace")
|
||||
clusterGenerator := NewClusterGenerator(t.Context(), cl, appClientset, "namespace")
|
||||
|
||||
applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package generators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
|
|
@ -293,7 +292,7 @@ func TestGenerateParamsForDuckType(t *testing.T) {
|
|||
|
||||
fakeDynClient := dynfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, testCase.resource)
|
||||
|
||||
duckTypeGenerator := NewDuckTypeGenerator(context.Background(), fakeDynClient, appClientset, "namespace")
|
||||
duckTypeGenerator := NewDuckTypeGenerator(t.Context(), fakeDynClient, appClientset, "namespace")
|
||||
|
||||
applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -589,7 +588,7 @@ func TestGenerateParamsForDuckTypeGoTemplate(t *testing.T) {
|
|||
|
||||
fakeDynClient := dynfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, testCase.resource)
|
||||
|
||||
duckTypeGenerator := NewDuckTypeGenerator(context.Background(), fakeDynClient, appClientset, "namespace")
|
||||
duckTypeGenerator := NewDuckTypeGenerator(t.Context(), fakeDynClient, appClientset, "namespace")
|
||||
|
||||
applicationSetInfo := argoprojiov1alpha1.ApplicationSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package generators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -644,7 +643,7 @@ func TestInterpolatedMatrixGenerate(t *testing.T) {
|
|||
fakeClient,
|
||||
testCase.clientError,
|
||||
}
|
||||
clusterGenerator := NewClusterGenerator(context.Background(), cl, appClientset, "namespace")
|
||||
clusterGenerator := NewClusterGenerator(t.Context(), cl, appClientset, "namespace")
|
||||
|
||||
for _, g := range testCaseCopy.baseGenerators {
|
||||
gitGeneratorSpec := v1alpha1.ApplicationSetGenerator{
|
||||
|
|
@ -827,7 +826,7 @@ func TestInterpolatedMatrixGenerateGoTemplate(t *testing.T) {
|
|||
fakeClient,
|
||||
testCase.clientError,
|
||||
}
|
||||
clusterGenerator := NewClusterGenerator(context.Background(), cl, appClientset, "namespace")
|
||||
clusterGenerator := NewClusterGenerator(t.Context(), cl, appClientset, "namespace")
|
||||
|
||||
for _, g := range testCaseCopy.baseGenerators {
|
||||
gitGeneratorSpec := v1alpha1.ApplicationSetGenerator{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package generators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -629,7 +628,7 @@ func TestPluginGenerateParams(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestPullRequestGithubGenerateParams(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
cases := []struct {
|
||||
selectFunc func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error)
|
||||
expected []map[string]any
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package http
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -118,7 +117,7 @@ func TestClientDo(t *testing.T) {
|
|||
client, err := NewClient(cc.fakeServer.URL, cc.clientOptionFns...)
|
||||
require.NoError(t, err, "NewClient returned unexpected error")
|
||||
|
||||
req, err := client.NewRequestWithContext(context.Background(), http.MethodPost, "", cc.params)
|
||||
req, err := client.NewRequestWithContext(t.Context(), http.MethodPost, "", cc.params)
|
||||
require.NoError(t, err, "NewRequest returned unexpected error")
|
||||
|
||||
var data []map[string]any
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
|
@ -34,7 +33,7 @@ func TestPlugin(t *testing.T) {
|
|||
client, err := NewPluginService("plugin-test", ts.URL, token, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
data, err := client.List(context.Background(), nil)
|
||||
data, err := client.List(t.Context(), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
var expectedData ServiceResponse
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func TestListPullRequest(t *testing.T) {
|
|||
prID := 123
|
||||
prTitle := "feat(123)"
|
||||
prHeadSha := "cd4973d9d14a08ffe6b641a89a68891d6aac8056"
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
uniqueName := "testName"
|
||||
|
||||
pullRequestMock := []git.GitPullRequest{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pull_request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -87,7 +86,7 @@ func TestListPullRequestBearerTokenCloud(t *testing.T) {
|
|||
defer ts.Close()
|
||||
svc, err := NewBitbucketCloudServiceBearerToken(ts.URL, "TOKEN", "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -105,7 +104,7 @@ func TestListPullRequestNoAuthCloud(t *testing.T) {
|
|||
defer ts.Close()
|
||||
svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -123,7 +122,7 @@ func TestListPullRequestBasicAuthCloud(t *testing.T) {
|
|||
defer ts.Close()
|
||||
svc, err := NewBitbucketCloudServiceBasicAuth(ts.URL, "user", "password", "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -214,7 +213,7 @@ func TestListPullRequestPaginationCloud(t *testing.T) {
|
|||
defer ts.Close()
|
||||
svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 3)
|
||||
assert.Equal(t, PullRequest{
|
||||
|
|
@ -246,7 +245,7 @@ func TestListResponseErrorCloud(t *testing.T) {
|
|||
}))
|
||||
defer ts.Close()
|
||||
svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
_, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
_, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -270,7 +269,7 @@ func TestListResponseMalformedCloud(t *testing.T) {
|
|||
}))
|
||||
defer ts.Close()
|
||||
svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
_, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
_, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +293,7 @@ func TestListResponseMalformedValuesCloud(t *testing.T) {
|
|||
}))
|
||||
defer ts.Close()
|
||||
svc, _ := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
_, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
_, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +318,7 @@ func TestListResponseEmptyCloud(t *testing.T) {
|
|||
defer ts.Close()
|
||||
svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, pullRequests)
|
||||
}
|
||||
|
|
@ -406,7 +405,7 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
|
|||
regexp := `feature-1[\d]{2}`
|
||||
svc, err := NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
@ -431,7 +430,7 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
|
|||
regexp = `.*2$`
|
||||
svc, err = NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
pullRequests, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
pullRequests, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
@ -449,7 +448,7 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
|
|||
regexp = `[\d{2}`
|
||||
svc, err = NewBitbucketCloudServiceNoAuth(ts.URL, "OWNER", "REPO")
|
||||
require.NoError(t, err)
|
||||
_, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
_, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pull_request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io"
|
||||
|
|
@ -64,9 +63,9 @@ func TestListPullRequestNoAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -165,9 +164,9 @@ func TestListPullRequestPagination(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 3)
|
||||
assert.Equal(t, PullRequest{
|
||||
|
|
@ -207,9 +206,9 @@ func TestListPullRequestBasicAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, err := NewBitbucketServiceBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceBasicAuth(t.Context(), "user", "password", ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -224,9 +223,9 @@ func TestListPullRequestBearerAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, err := NewBitbucketServiceBearerToken(context.Background(), "tolkien", ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceBearerToken(t.Context(), "tolkien", ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, 101, pullRequests[0].Number)
|
||||
|
|
@ -290,9 +289,9 @@ func TestListPullRequestTLS(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
svc, err := NewBitbucketServiceBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", "REPO", "", test.tlsInsecure, certs)
|
||||
svc, err := NewBitbucketServiceBasicAuth(t.Context(), "user", "password", ts.URL, "PROJECT", "REPO", "", test.tlsInsecure, certs)
|
||||
require.NoError(t, err)
|
||||
_, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
_, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
if test.requireErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
@ -307,8 +306,8 @@ func TestListResponseError(t *testing.T) {
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, _ := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
_, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
svc, _ := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
_, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -332,8 +331,8 @@ func TestListResponseMalformed(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, _ := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
_, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
svc, _ := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
_, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -357,9 +356,9 @@ func TestListResponseEmpty(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, pullRequests)
|
||||
}
|
||||
|
|
@ -453,9 +452,9 @@ func TestListPullRequestBranchMatch(t *testing.T) {
|
|||
}))
|
||||
defer ts.Close()
|
||||
regexp := `feature-1[\d]{2}`
|
||||
svc, err := NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err := NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err := ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
pullRequests, err := ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
@ -482,9 +481,9 @@ func TestListPullRequestBranchMatch(t *testing.T) {
|
|||
}, *pullRequests[1])
|
||||
|
||||
regexp = `.*2$`
|
||||
svc, err = NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err = NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
pullRequests, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
pullRequests, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
@ -502,9 +501,9 @@ func TestListPullRequestBranchMatch(t *testing.T) {
|
|||
}, *pullRequests[0])
|
||||
|
||||
regexp = `[\d{2}`
|
||||
svc, err = NewBitbucketServiceNoAuth(context.Background(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
svc, err = NewBitbucketServiceNoAuth(t.Context(), ts.URL, "PROJECT", "REPO", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
_, err = ListPullRequests(context.Background(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
_, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
|
||||
{
|
||||
BranchMatch: ®exp,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pull_request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -253,7 +252,7 @@ func TestGiteaList(t *testing.T) {
|
|||
}))
|
||||
host, err := NewGiteaService("", ts.URL, "test-argocd", "pr-test", false)
|
||||
require.NoError(t, err)
|
||||
prs, err := host.List(context.Background())
|
||||
prs, err := host.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, prs, 1)
|
||||
assert.Equal(t, 1, prs[0].Number)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pull_request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io"
|
||||
|
|
@ -38,7 +37,7 @@ func TestGitLabServiceCustomBaseURL(t *testing.T) {
|
|||
svc, err := NewGitLabService("", server.URL, "278964", nil, "", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = svc.List(context.Background())
|
||||
_, err = svc.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +56,7 @@ func TestGitLabServiceToken(t *testing.T) {
|
|||
svc, err := NewGitLabService("token-123", server.URL, "278964", nil, "", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = svc.List(context.Background())
|
||||
_, err = svc.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ func TestList(t *testing.T) {
|
|||
svc, err := NewGitLabService("", server.URL, "278964", []string{}, "", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
prs, err := svc.List(context.Background())
|
||||
prs, err := svc.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, prs, 1)
|
||||
assert.Equal(t, 15442, prs[0].Number)
|
||||
|
|
@ -102,7 +101,7 @@ func TestListWithLabels(t *testing.T) {
|
|||
svc, err := NewGitLabService("", server.URL, "278964", []string{"feature", "ready"}, "", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = svc.List(context.Background())
|
||||
_, err = svc.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +120,7 @@ func TestListWithState(t *testing.T) {
|
|||
svc, err := NewGitLabService("", server.URL, "278964", []string{}, "opened", "", false, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = svc.List(context.Background())
|
||||
_, err = svc.List(t.Context())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +182,7 @@ func TestListWithStateTLS(t *testing.T) {
|
|||
svc, err := NewGitLabService("", ts.URL, "278964", []string{}, "opened", "", test.tlsInsecure, certs)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = svc.List(context.Background())
|
||||
_, err = svc.List(t.Context())
|
||||
if test.requireErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package pull_request
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -16,7 +15,7 @@ func strp(s string) *string {
|
|||
|
||||
func TestFilterBranchMatchBadRegexp(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -34,13 +33,13 @@ func TestFilterBranchMatchBadRegexp(t *testing.T) {
|
|||
BranchMatch: strp("("),
|
||||
},
|
||||
}
|
||||
_, err := ListPullRequests(context.Background(), provider, filters)
|
||||
_, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestFilterBranchMatch(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -82,7 +81,7 @@ func TestFilterBranchMatch(t *testing.T) {
|
|||
BranchMatch: strp("w"),
|
||||
},
|
||||
}
|
||||
pullRequests, err := ListPullRequests(context.Background(), provider, filters)
|
||||
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, "two", pullRequests[0].Branch)
|
||||
|
|
@ -90,7 +89,7 @@ func TestFilterBranchMatch(t *testing.T) {
|
|||
|
||||
func TestFilterTargetBranchMatch(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -132,7 +131,7 @@ func TestFilterTargetBranchMatch(t *testing.T) {
|
|||
TargetBranchMatch: strp("1"),
|
||||
},
|
||||
}
|
||||
pullRequests, err := ListPullRequests(context.Background(), provider, filters)
|
||||
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 1)
|
||||
assert.Equal(t, "two", pullRequests[0].Branch)
|
||||
|
|
@ -140,7 +139,7 @@ func TestFilterTargetBranchMatch(t *testing.T) {
|
|||
|
||||
func TestMultiFilterOr(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -185,7 +184,7 @@ func TestMultiFilterOr(t *testing.T) {
|
|||
BranchMatch: strp("r"),
|
||||
},
|
||||
}
|
||||
pullRequests, err := ListPullRequests(context.Background(), provider, filters)
|
||||
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 3)
|
||||
assert.Equal(t, "two", pullRequests[0].Branch)
|
||||
|
|
@ -195,7 +194,7 @@ func TestMultiFilterOr(t *testing.T) {
|
|||
|
||||
func TestMultiFilterOrWithTargetBranchFilter(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -242,7 +241,7 @@ func TestMultiFilterOrWithTargetBranchFilter(t *testing.T) {
|
|||
TargetBranchMatch: strp("3"),
|
||||
},
|
||||
}
|
||||
pullRequests, err := ListPullRequests(context.Background(), provider, filters)
|
||||
pullRequests, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pullRequests, 2)
|
||||
assert.Equal(t, "two", pullRequests[0].Branch)
|
||||
|
|
@ -251,7 +250,7 @@ func TestMultiFilterOrWithTargetBranchFilter(t *testing.T) {
|
|||
|
||||
func TestNoFilters(t *testing.T) {
|
||||
provider, _ := NewFakeService(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
[]*PullRequest{
|
||||
{
|
||||
Number: 1,
|
||||
|
|
@ -273,7 +272,7 @@ func TestNoFilters(t *testing.T) {
|
|||
nil,
|
||||
)
|
||||
filters := []argoprojiov1alpha1.PullRequestGeneratorFilter{}
|
||||
repos, err := ListPullRequests(context.Background(), provider, filters)
|
||||
repos, err := ListPullRequests(t.Context(), provider, filters)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
assert.Equal(t, "one", repos[0].Branch)
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ func TestGetFiles(t *testing.T) {
|
|||
func TestNewArgoCDService(t *testing.T) {
|
||||
testNamespace := "test"
|
||||
clientset := fake.NewClientset()
|
||||
testDB := db.NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
testDB := db.NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
service := NewArgoCDService(testDB, false, &repo_mocks.Clientset{}, false)
|
||||
assert.NotNil(t, service)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"testing"
|
||||
|
|
@ -160,7 +159,7 @@ func TestAWSCodeCommitListRepos(t *testing.T) {
|
|||
t.Run(testCase.name, func(t *testing.T) {
|
||||
codeCommitClient := mocks.NewAWSCodeCommitClient(t)
|
||||
taggingClient := mocks.NewAWSTaggingClient(t)
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
codecommitRepoNameIdPairs := make([]*codecommit.RepositoryNameIdPair, 0)
|
||||
resourceTaggings := make([]*resourcegroupstaggingapi.ResourceTagMapping, 0)
|
||||
validRepositories := make([]*awsCodeCommitTestRepository, 0)
|
||||
|
|
@ -349,7 +348,7 @@ func TestAWSCodeCommitRepoHasPath(t *testing.T) {
|
|||
t.Run(testCase.name, func(t *testing.T) {
|
||||
codeCommitClient := mocks.NewAWSCodeCommitClient(t)
|
||||
taggingClient := mocks.NewAWSTaggingClient(t)
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if testCase.expectedGetFolderPath != "" {
|
||||
codeCommitClient.
|
||||
On("GetFolderWithContext", ctx, &codecommit.GetFolderInput{
|
||||
|
|
@ -422,7 +421,7 @@ func TestAWSCodeCommitGetBranches(t *testing.T) {
|
|||
t.Run(testCase.name, func(t *testing.T) {
|
||||
codeCommitClient := mocks.NewAWSCodeCommitClient(t)
|
||||
taggingClient := mocks.NewAWSTaggingClient(t)
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if testCase.allBranches {
|
||||
codeCommitClient.
|
||||
On("ListBranchesWithContext", ctx, &codecommit.ListBranchesInput{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func TestAzureDevopsRepoHasPath(t *testing.T) {
|
|||
path := "dir/subdir/item.yaml"
|
||||
branchName := "my/featurebranch"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
uuid := uuid.New().String()
|
||||
|
||||
testCases := []struct {
|
||||
|
|
@ -115,7 +115,7 @@ func TestGetDefaultBranchOnDisabledRepo(t *testing.T) {
|
|||
repoName := "myorg_project_repo"
|
||||
defaultBranch := "main"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
|
@ -174,7 +174,7 @@ func TestGetAllBranchesOnDisabledRepo(t *testing.T) {
|
|||
repoName := "myorg_project_repo"
|
||||
defaultBranch := "main"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
|
@ -233,7 +233,7 @@ func TestAzureDevOpsGetDefaultBranchStripsRefsName(t *testing.T) {
|
|||
teamProject := "myorg_project"
|
||||
repoName := "myorg_project_repo"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
uuid := uuid.New().String()
|
||||
strippedBranchName := "somebranch"
|
||||
defaultBranch := fmt.Sprintf("refs/heads/%v", strippedBranchName)
|
||||
|
|
@ -264,7 +264,7 @@ func TestAzureDevOpsGetBranchesDefultBranchOnly(t *testing.T) {
|
|||
teamProject := "myorg_project"
|
||||
repoName := "myorg_project_repo"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
uuid := uuid.New().String()
|
||||
|
||||
defaultBranch := "main"
|
||||
|
|
@ -335,7 +335,7 @@ func TestAzureDevopsGetBranches(t *testing.T) {
|
|||
teamProject := "myorg_project"
|
||||
repoName := "myorg_project_repo"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
uuid := uuid.New().String()
|
||||
|
||||
testCases := []struct {
|
||||
|
|
@ -427,7 +427,7 @@ func TestGetAzureDevopsRepositories(t *testing.T) {
|
|||
teamProject := "myorg_project"
|
||||
|
||||
uuid := uuid.New()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
repoId := &uuid
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -94,7 +93,7 @@ func TestBitbucketHasRepo(t *testing.T) {
|
|||
SHA: c.sha,
|
||||
Branch: "main",
|
||||
}
|
||||
hasPath, err := provider.RepoHasPath(context.Background(), repo, c.path)
|
||||
hasPath, err := provider.RepoHasPath(t.Context(), repo, c.path)
|
||||
if err != nil {
|
||||
require.Error(t, fmt.Errorf("Error in test %w", err))
|
||||
}
|
||||
|
|
@ -488,7 +487,7 @@ func TestBitbucketListRepos(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
provider, _ := NewBitBucketCloudProvider(c.owner, "user", "password", c.allBranches)
|
||||
rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
|
||||
rawRepos, err := ListRepos(t.Context(), provider, c.filters, c.proto)
|
||||
if c.hasError {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"io"
|
||||
|
|
@ -103,9 +102,9 @@ func TestListReposNoAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
verifyDefaultRepo(t, err, repos)
|
||||
}
|
||||
|
||||
|
|
@ -195,9 +194,9 @@ func TestListReposPagination(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
assert.Equal(t, Repository{
|
||||
|
|
@ -272,9 +271,9 @@ func TestGetBranchesBranchPagination(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.GetBranches(context.Background(), &Repository{
|
||||
repos, err := provider.GetBranches(t.Context(), &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
URL: "ssh://git@mycompany.bitbucket.org/PROJECT/REPO.git",
|
||||
|
|
@ -324,9 +323,9 @@ func TestGetBranchesDefaultOnly(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.GetBranches(context.Background(), &Repository{
|
||||
repos, err := provider.GetBranches(t.Context(), &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
URL: "ssh://git@mycompany.bitbucket.org/PROJECT/REPO.git",
|
||||
|
|
@ -355,9 +354,9 @@ func TestGetBranchesMissingDefault(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.GetBranches(context.Background(), &Repository{
|
||||
repos, err := provider.GetBranches(t.Context(), &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
URL: "ssh://git@mycompany.bitbucket.org/PROJECT/REPO.git",
|
||||
|
|
@ -376,9 +375,9 @@ func TestGetBranchesEmptyRepo(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.GetBranches(context.Background(), &Repository{
|
||||
repos, err := provider.GetBranches(t.Context(), &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
URL: "ssh://git@mycompany.bitbucket.org/PROJECT/REPO.git",
|
||||
|
|
@ -398,9 +397,9 @@ func TestGetBranchesErrorDefaultBranch(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
_, err = provider.GetBranches(context.Background(), &Repository{
|
||||
_, err = provider.GetBranches(t.Context(), &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
URL: "ssh://git@mycompany.bitbucket.org/PROJECT/REPO.git",
|
||||
|
|
@ -465,9 +464,9 @@ func TestListReposTLS(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
provider, err := NewBitbucketServerProviderBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", true, "", test.tlsInsecure, certs)
|
||||
provider, err := NewBitbucketServerProviderBasicAuth(t.Context(), "user", "password", ts.URL, "PROJECT", true, "", test.tlsInsecure, certs)
|
||||
require.NoError(t, err)
|
||||
_, err = provider.ListRepos(context.Background(), "ssh")
|
||||
_, err = provider.ListRepos(t.Context(), "ssh")
|
||||
if test.requireErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
@ -484,9 +483,9 @@ func TestListReposBasicAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderBasicAuth(context.Background(), "user", "password", ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderBasicAuth(t.Context(), "user", "password", ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
verifyDefaultRepo(t, err, repos)
|
||||
}
|
||||
|
||||
|
|
@ -497,9 +496,9 @@ func TestListReposBearerAuth(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderBearerToken(context.Background(), "tolkien", ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderBearerToken(t.Context(), "tolkien", ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
verifyDefaultRepo(t, err, repos)
|
||||
}
|
||||
|
||||
|
|
@ -523,9 +522,9 @@ func TestListReposDefaultBranch(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, Repository{
|
||||
|
|
@ -548,9 +547,9 @@ func TestListReposMissingDefaultBranch(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "ssh")
|
||||
repos, err := provider.ListRepos(t.Context(), "ssh")
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, repos)
|
||||
}
|
||||
|
|
@ -564,9 +563,9 @@ func TestListReposErrorDefaultBranch(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", false, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
_, err = provider.ListRepos(context.Background(), "ssh")
|
||||
_, err = provider.ListRepos(t.Context(), "ssh")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -576,9 +575,9 @@ func TestListReposCloneProtocol(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repos, err := provider.ListRepos(context.Background(), "https")
|
||||
repos, err := provider.ListRepos(t.Context(), "https")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, Repository{
|
||||
|
|
@ -598,9 +597,9 @@ func TestListReposUnknownProtocol(t *testing.T) {
|
|||
defaultHandler(t)(w, r)
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
_, errProtocol := provider.ListRepos(context.Background(), "http")
|
||||
_, errProtocol := provider.ListRepos(t.Context(), "http")
|
||||
require.Error(t, errProtocol)
|
||||
}
|
||||
|
||||
|
|
@ -636,37 +635,37 @@ func TestBitbucketServerHasPath(t *testing.T) {
|
|||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
provider, err := NewBitbucketServerProviderNoAuth(context.Background(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
provider, err := NewBitbucketServerProviderNoAuth(t.Context(), ts.URL, "PROJECT", true, "", false, nil)
|
||||
require.NoError(t, err)
|
||||
repo := &Repository{
|
||||
Organization: "PROJECT",
|
||||
Repository: "REPO",
|
||||
Branch: "main",
|
||||
}
|
||||
ok, err := provider.RepoHasPath(context.Background(), repo, "pkg")
|
||||
ok, err := provider.RepoHasPath(t.Context(), repo, "pkg")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
ok, err = provider.RepoHasPath(context.Background(), repo, "pkg/")
|
||||
ok, err = provider.RepoHasPath(t.Context(), repo, "pkg/")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
ok, err = provider.RepoHasPath(context.Background(), repo, "anotherpkg/file.txt")
|
||||
ok, err = provider.RepoHasPath(t.Context(), repo, "anotherpkg/file.txt")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
ok, err = provider.RepoHasPath(context.Background(), repo, "anotherpkg/missing.txt")
|
||||
ok, err = provider.RepoHasPath(t.Context(), repo, "anotherpkg/missing.txt")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, ok)
|
||||
|
||||
ok, err = provider.RepoHasPath(context.Background(), repo, "notathing")
|
||||
ok, err = provider.RepoHasPath(t.Context(), repo, "notathing")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, ok)
|
||||
|
||||
ok, err = provider.RepoHasPath(context.Background(), repo, "return-redirect")
|
||||
ok, err = provider.RepoHasPath(t.Context(), repo, "return-redirect")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
_, err = provider.RepoHasPath(context.Background(), repo, "unauthorized-response")
|
||||
_, err = provider.RepoHasPath(t.Context(), repo, "unauthorized-response")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -305,7 +304,7 @@ func TestGiteaListRepos(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
provider, _ := NewGiteaProvider("test-argocd", "", ts.URL, c.allBranches, false)
|
||||
rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
|
||||
rawRepos, err := ListRepos(t.Context(), provider, c.filters, c.proto)
|
||||
if c.hasError {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
@ -342,19 +341,19 @@ func TestGiteaHasPath(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("file exists", func(t *testing.T) {
|
||||
ok, err := host.RepoHasPath(context.Background(), repo, "README.md")
|
||||
ok, err := host.RepoHasPath(t.Context(), repo, "README.md")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
})
|
||||
|
||||
t.Run("directory exists", func(t *testing.T) {
|
||||
ok, err := host.RepoHasPath(context.Background(), repo, "gitea")
|
||||
ok, err := host.RepoHasPath(t.Context(), repo, "gitea")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
})
|
||||
|
||||
t.Run("does not exists", func(t *testing.T) {
|
||||
ok, err := host.RepoHasPath(context.Background(), repo, "notathing")
|
||||
ok, err := host.RepoHasPath(t.Context(), repo, "notathing")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, ok)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -244,7 +243,7 @@ func TestGithubListRepos(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
provider, _ := NewGithubProvider("argoproj", "", ts.URL, c.allBranches)
|
||||
rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
|
||||
rawRepos, err := ListRepos(t.Context(), provider, c.filters, c.proto)
|
||||
if c.hasError {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
@ -279,11 +278,11 @@ func TestGithubHasPath(t *testing.T) {
|
|||
Repository: "argo-cd",
|
||||
Branch: "master",
|
||||
}
|
||||
ok, err := host.RepoHasPath(context.Background(), repo, "pkg/")
|
||||
ok, err := host.RepoHasPath(t.Context(), repo, "pkg/")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
ok, err = host.RepoHasPath(context.Background(), repo, "notathing/")
|
||||
ok, err = host.RepoHasPath(t.Context(), repo, "notathing/")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, ok)
|
||||
}
|
||||
|
|
@ -299,7 +298,7 @@ func TestGithubGetBranches(t *testing.T) {
|
|||
Repository: "argo-cd",
|
||||
Branch: "master",
|
||||
}
|
||||
repos, err := host.GetBranches(context.Background(), repo)
|
||||
repos, err := host.GetBranches(t.Context(), repo)
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
|
|
@ -311,12 +310,12 @@ func TestGithubGetBranches(t *testing.T) {
|
|||
Repository: "applicationset",
|
||||
Branch: "main",
|
||||
}
|
||||
_, err = host.GetBranches(context.Background(), repo2)
|
||||
_, err = host.GetBranches(t.Context(), repo2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get all branches
|
||||
host.allBranches = true
|
||||
repos, err = host.GetBranches(context.Background(), repo)
|
||||
repos, err = host.GetBranches(t.Context(), repo)
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
|
|
@ -1152,7 +1151,7 @@ func TestGitlabListRepos(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
provider, _ := NewGitlabProvider("test-argocd-proton", "", ts.URL, c.allBranches, c.includeSubgroups, c.includeSharedProjects, c.insecure, "", c.topic, nil)
|
||||
rawRepos, err := ListRepos(context.Background(), provider, c.filters, c.proto)
|
||||
rawRepos, err := ListRepos(t.Context(), provider, c.filters, c.proto)
|
||||
if c.hasError {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
@ -1235,7 +1234,7 @@ func TestGitlabHasPath(t *testing.T) {
|
|||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
ok, err := host.RepoHasPath(context.Background(), repo, c.path)
|
||||
ok, err := host.RepoHasPath(t.Context(), repo, c.path)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, c.exists, ok)
|
||||
})
|
||||
|
|
@ -1253,7 +1252,7 @@ func TestGitlabGetBranches(t *testing.T) {
|
|||
Branch: "master",
|
||||
}
|
||||
t.Run("branch exists", func(t *testing.T) {
|
||||
repos, err := host.GetBranches(context.Background(), repo)
|
||||
repos, err := host.GetBranches(t.Context(), repo)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "master", repos[0].Branch)
|
||||
})
|
||||
|
|
@ -1263,7 +1262,7 @@ func TestGitlabGetBranches(t *testing.T) {
|
|||
Branch: "foo",
|
||||
}
|
||||
t.Run("unknown branch", func(t *testing.T) {
|
||||
_, err := host.GetBranches(context.Background(), repo2)
|
||||
_, err := host.GetBranches(t.Context(), repo2)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
@ -1329,7 +1328,7 @@ func TestGetBranchesTLS(t *testing.T) {
|
|||
RepositoryId: 27084533,
|
||||
Branch: "master",
|
||||
}
|
||||
_, err = host.GetBranches(context.Background(), repo)
|
||||
_, err = host.GetBranches(t.Context(), repo)
|
||||
if test.requireErr {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package scm_provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ func TestFilterRepoMatch(t *testing.T) {
|
|||
RepositoryMatch: strp("n|hr"),
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
assert.Equal(t, "one", repos[0].Repository)
|
||||
|
|
@ -66,7 +65,7 @@ func TestFilterLabelMatch(t *testing.T) {
|
|||
LabelMatch: strp("^prod-.*$"),
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
assert.Equal(t, "one", repos[0].Repository)
|
||||
|
|
@ -92,7 +91,7 @@ func TestFilterPathExists(t *testing.T) {
|
|||
PathsExist: []string{"two"},
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, "two", repos[0].Repository)
|
||||
|
|
@ -117,7 +116,7 @@ func TestFilterPathDoesntExists(t *testing.T) {
|
|||
PathsDoNotExist: []string{"two"},
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
}
|
||||
|
|
@ -135,7 +134,7 @@ func TestFilterRepoMatchBadRegexp(t *testing.T) {
|
|||
RepositoryMatch: strp("("),
|
||||
},
|
||||
}
|
||||
_, err := ListRepos(context.Background(), provider, filters, "")
|
||||
_, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +151,7 @@ func TestFilterLabelMatchBadRegexp(t *testing.T) {
|
|||
LabelMatch: strp("("),
|
||||
},
|
||||
}
|
||||
_, err := ListRepos(context.Background(), provider, filters, "")
|
||||
_, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +185,7 @@ func TestFilterBranchMatch(t *testing.T) {
|
|||
BranchMatch: strp("w"),
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 2)
|
||||
assert.Equal(t, "one", repos[0].Repository)
|
||||
|
|
@ -218,7 +217,7 @@ func TestMultiFilterAnd(t *testing.T) {
|
|||
LabelMatch: strp("^prod-.*$"),
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, "two", repos[0].Repository)
|
||||
|
|
@ -249,7 +248,7 @@ func TestMultiFilterOr(t *testing.T) {
|
|||
LabelMatch: strp("^prod-.*$"),
|
||||
},
|
||||
}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 3)
|
||||
assert.Equal(t, "one", repos[0].Repository)
|
||||
|
|
@ -275,7 +274,7 @@ func TestNoFilters(t *testing.T) {
|
|||
},
|
||||
}
|
||||
filters := []argoprojiov1alpha1.SCMProviderGeneratorFilter{}
|
||||
repos, err := ListRepos(context.Background(), provider, filters, "")
|
||||
repos, err := ListRepos(t.Context(), provider, filters, "")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 3)
|
||||
assert.Equal(t, "one", repos[0].Repository)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -21,7 +20,7 @@ func TestGetSecretRef(t *testing.T) {
|
|||
},
|
||||
}
|
||||
client := fake.NewClientBuilder().WithObjects(secret).Build()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
cases := []struct {
|
||||
name, namespace, token string
|
||||
|
|
@ -86,7 +85,7 @@ func TestGetConfigMapData(t *testing.T) {
|
|||
},
|
||||
}
|
||||
client := fake.NewClientBuilder().WithObjects(configMap).Build()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
cases := []struct {
|
||||
name, namespace, data string
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package webhook
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -230,7 +229,7 @@ func TestWebhookHandler(t *testing.T) {
|
|||
fakeAppWithMergeAndPullRequestGenerator("merge-pull-request-github", namespace, "Codertocat", "Hello-World"),
|
||||
fakeAppWithMergeAndNestedGitGenerator("merge-nested-git-github", namespace, "https://github.com/org/repo"),
|
||||
).Build()
|
||||
set := argosettings.NewSettingsManager(context.TODO(), fakeClient, namespace)
|
||||
set := argosettings.NewSettingsManager(t.Context(), fakeClient, namespace)
|
||||
h, err := NewWebhookHandler(namespace, webhookParallelism, set, fc, mockGenerators())
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -247,7 +246,7 @@ func TestWebhookHandler(t *testing.T) {
|
|||
assert.Equal(t, test.expectedStatusCode, w.Code)
|
||||
|
||||
list := &v1alpha1.ApplicationSetList{}
|
||||
err = fc.List(context.TODO(), list)
|
||||
err = fc.List(t.Context(), list)
|
||||
require.NoError(t, err)
|
||||
effectedAppSetsAsExpected := make(map[string]bool)
|
||||
for _, appSetName := range test.effectedAppSets {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -11,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetSignedRequestWithRetry(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
t.Run("will return signed request on first attempt", func(t *testing.T) {
|
||||
// given
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -69,7 +68,7 @@ func TestGetAdditionalNamespaces(t *testing.T) {
|
|||
projects: fakeDynClient.Resource(schema.GroupVersionResource{}),
|
||||
}
|
||||
|
||||
result := getAdditionalNamespaces(context.TODO(), argoCDClientsets)
|
||||
result := getAdditionalNamespaces(t.Context(), argoCDClientsets)
|
||||
assert.Equal(t, c.expected, *result)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
clustermocks "github.com/argoproj/gitops-engine/pkg/cache/mocks"
|
||||
|
|
@ -31,7 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetReconcileResults(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
appClientset := appfake.NewSimpleClientset(&v1alpha1.Application{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -56,7 +55,7 @@ func TestGetReconcileResults(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetReconcileResults_Refresh(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
argoCM := &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ func Test_loadClusters(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
kubeClient := fake.NewClientset(argoCDCM, argoCDSecret)
|
||||
appClient := fakeapps.NewSimpleClientset(app)
|
||||
cacheSrc := func() (*appstate.Cache, error) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -30,7 +29,7 @@ func newProj(name string, roleNames ...string) *v1alpha1.AppProject {
|
|||
}
|
||||
|
||||
func TestUpdateProjects_FindMatchingProject(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
clientset := fake.NewSimpleClientset(newProj("foo", "test"), newProj("bar", "test"))
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ func TestUpdateProjects_FindMatchingProject(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateProjects_FindMatchingRole(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
clientset := fake.NewSimpleClientset(newProj("proj", "foo", "bar"))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -116,7 +115,7 @@ func Test_validateRBACResourceAction(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_PolicyFromCSV(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
uPol, dRole, matchMode := getPolicy(ctx, "testdata/rbac/policy.csv", nil, "")
|
||||
require.NotEmpty(t, uPol)
|
||||
|
|
@ -125,7 +124,7 @@ func Test_PolicyFromCSV(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_PolicyFromYAML(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
uPol, dRole, matchMode := getPolicy(ctx, "testdata/rbac/argocd-rbac-cm.yaml", nil, "")
|
||||
require.NotEmpty(t, uPol)
|
||||
|
|
@ -137,7 +136,7 @@ func Test_PolicyFromYAML(t *testing.T) {
|
|||
|
||||
func Test_PolicyFromK8s(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/rbac/policy.csv")
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
require.NoError(t, err)
|
||||
kubeclientset := fake.NewClientset(&corev1.ConfigMap{
|
||||
|
|
@ -218,7 +217,7 @@ func Test_PolicyFromK8s(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_PolicyFromK8sUsingRegex(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
policy := `
|
||||
p, role:user, clusters, get, .+, allow
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ type validatorTestCase struct {
|
|||
}
|
||||
|
||||
func TestCreateSettingsManager(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
f, closer, err := tempFile(`apiVersion: v1
|
||||
kind: ConfigMap
|
||||
|
|
|
|||
|
|
@ -1029,11 +1029,10 @@ func TestTargetObjects_invalid(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestCheckForDeleteEvent(_ *testing.T) {
|
||||
ctx := context.Background()
|
||||
func TestCheckForDeleteEvent(t *testing.T) {
|
||||
fakeClient := new(fakeAcdClient)
|
||||
|
||||
checkForDeleteEvent(ctx, fakeClient, "testApp")
|
||||
checkForDeleteEvent(t.Context(), fakeClient, "testApp")
|
||||
}
|
||||
|
||||
func TestPrintApplicationNames(t *testing.T) {
|
||||
|
|
@ -1872,7 +1871,7 @@ func testApp(name, project string, labels map[string]string, annotations map[str
|
|||
|
||||
func TestWaitOnApplicationStatus_JSON_YAML_WideOutput(t *testing.T) {
|
||||
acdClient := &customAcdClient{&fakeAcdClient{}}
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
var selectResource []*v1alpha1.SyncOperationResource
|
||||
watch := watchOpts{
|
||||
sync: false,
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -115,7 +115,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -130,7 +130,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
_, _, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
_, _, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.ErrorContains(t, err, "syntax error")
|
||||
|
|
@ -145,7 +145,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -162,7 +162,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -179,7 +179,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
_, _, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
_, _, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.ErrorContains(t, err, "error finding glob match for pattern")
|
||||
|
|
@ -196,7 +196,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -215,7 +215,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
assert.False(t, match)
|
||||
|
|
@ -233,7 +233,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -253,7 +253,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -272,7 +272,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.Error(t, err)
|
||||
|
|
@ -285,7 +285,7 @@ func TestMatchRepository(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
match, discovery, err := f.service.matchRepository(context.Background(), f.path, f.env, ".")
|
||||
match, discovery, err := f.service.matchRepository(t.Context(), f.path, f.env, ".")
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -308,7 +308,7 @@ func TestGenerateManifest(t *testing.T) {
|
|||
service, err := newService(configFilePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
res1, err := service.generateManifest(context.Background(), "testdata/kustomize", nil)
|
||||
res1, err := service.generateManifest(t.Context(), "testdata/kustomize", nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res1)
|
||||
|
||||
|
|
@ -322,7 +322,7 @@ func TestGenerateManifest(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
service.WithGenerateCommand(Command{Command: []string{"bad-command"}})
|
||||
|
||||
res, err := service.generateManifest(context.Background(), "testdata/kustomize", nil)
|
||||
res, err := service.generateManifest(t.Context(), "testdata/kustomize", nil)
|
||||
require.ErrorContains(t, err, "executable file not found")
|
||||
assert.Nil(t, res.Manifests)
|
||||
})
|
||||
|
|
@ -331,7 +331,7 @@ func TestGenerateManifest(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
service.WithGenerateCommand(Command{Command: []string{"echo", "invalid yaml: }"}})
|
||||
|
||||
res, err := service.generateManifest(context.Background(), "testdata/kustomize", nil)
|
||||
res, err := service.generateManifest(t.Context(), "testdata/kustomize", nil)
|
||||
require.ErrorContains(t, err, "failed to unmarshal manifest")
|
||||
assert.Nil(t, res.Manifests)
|
||||
})
|
||||
|
|
@ -342,7 +342,7 @@ func TestGenerateManifest_deadline_exceeded(t *testing.T) {
|
|||
service, err := newService(configFilePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
expiredCtx, cancel := context.WithTimeout(context.Background(), time.Second*0)
|
||||
expiredCtx, cancel := context.WithTimeout(t.Context(), time.Second*0)
|
||||
defer cancel()
|
||||
_, err = service.generateManifest(expiredCtx, "", nil)
|
||||
require.ErrorContains(t, err, "context deadline exceeded")
|
||||
|
|
@ -350,7 +350,7 @@ func TestGenerateManifest_deadline_exceeded(t *testing.T) {
|
|||
|
||||
// TestRunCommandContextTimeout makes sure the command dies at timeout rather than sleeping past the timeout.
|
||||
func TestRunCommandContextTimeout(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 990*time.Millisecond)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 990*time.Millisecond)
|
||||
defer cancel()
|
||||
// Use a subshell so there's a child command.
|
||||
command := Command{
|
||||
|
|
@ -365,13 +365,13 @@ func TestRunCommandContextTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRunCommandEmptyCommand(t *testing.T) {
|
||||
_, err := runCommand(context.Background(), Command{}, "", nil)
|
||||
_, err := runCommand(t.Context(), Command{}, "", nil)
|
||||
require.ErrorContains(t, err, "Command is empty")
|
||||
}
|
||||
|
||||
// TestRunCommandContextTimeoutWithCleanup makes sure that the process is given enough time to cleanup before sending SIGKILL.
|
||||
func TestRunCommandContextTimeoutWithCleanup(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 900*time.Millisecond)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 900*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
// Use a subshell so there's a child command.
|
||||
|
|
@ -403,7 +403,7 @@ func Test_getParametersAnnouncement_empty_command(t *testing.T) {
|
|||
Command: []string{"echo"},
|
||||
Args: []string{`[]`},
|
||||
}
|
||||
res, err := getParametersAnnouncement(context.Background(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
res, err := getParametersAnnouncement(t.Context(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*repoclient.ParameterAnnouncement{{Name: "static-a"}, {Name: "static-b"}}, res.ParameterAnnouncements)
|
||||
}
|
||||
|
|
@ -417,7 +417,7 @@ func Test_getParametersAnnouncement_no_command(t *testing.T) {
|
|||
err := yaml.Unmarshal([]byte(staticYAML), static)
|
||||
require.NoError(t, err)
|
||||
command := Command{}
|
||||
res, err := getParametersAnnouncement(context.Background(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
res, err := getParametersAnnouncement(t.Context(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*repoclient.ParameterAnnouncement{{Name: "static-a"}, {Name: "static-b"}}, res.ParameterAnnouncements)
|
||||
}
|
||||
|
|
@ -434,7 +434,7 @@ func Test_getParametersAnnouncement_static_and_dynamic(t *testing.T) {
|
|||
Command: []string{"echo"},
|
||||
Args: []string{`[{"name": "dynamic-a"}, {"name": "dynamic-b"}]`},
|
||||
}
|
||||
res, err := getParametersAnnouncement(context.Background(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
res, err := getParametersAnnouncement(t.Context(), "", *static, command, []*apiclient.EnvEntry{})
|
||||
require.NoError(t, err)
|
||||
expected := []*repoclient.ParameterAnnouncement{
|
||||
{Name: "dynamic-a"},
|
||||
|
|
@ -450,7 +450,7 @@ func Test_getParametersAnnouncement_invalid_json(t *testing.T) {
|
|||
Command: []string{"echo"},
|
||||
Args: []string{`[`},
|
||||
}
|
||||
_, err := getParametersAnnouncement(context.Background(), "", []*repoclient.ParameterAnnouncement{}, command, []*apiclient.EnvEntry{})
|
||||
_, err := getParametersAnnouncement(t.Context(), "", []*repoclient.ParameterAnnouncement{}, command, []*apiclient.EnvEntry{})
|
||||
assert.ErrorContains(t, err, "unexpected end of JSON input")
|
||||
}
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ func Test_getParametersAnnouncement_bad_command(t *testing.T) {
|
|||
Command: []string{"exit"},
|
||||
Args: []string{"1"},
|
||||
}
|
||||
_, err := getParametersAnnouncement(context.Background(), "", []*repoclient.ParameterAnnouncement{}, command, []*apiclient.EnvEntry{})
|
||||
_, err := getParametersAnnouncement(t.Context(), "", []*repoclient.ParameterAnnouncement{}, command, []*apiclient.EnvEntry{})
|
||||
assert.ErrorContains(t, err, "error executing dynamic parameter output command")
|
||||
}
|
||||
|
||||
|
|
@ -868,7 +868,7 @@ func TestService_CheckPluginConfiguration(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
resp, err := f.service.CheckPluginConfiguration(context.Background(), &empty.Empty{})
|
||||
resp, err := f.service.CheckPluginConfiguration(t.Context(), &empty.Empty{})
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
@ -881,7 +881,7 @@ func TestService_CheckPluginConfiguration(t *testing.T) {
|
|||
f := setup(t, withDiscover(d))
|
||||
|
||||
// when
|
||||
resp, err := f.service.CheckPluginConfiguration(context.Background(), &empty.Empty{})
|
||||
resp, err := f.service.CheckPluginConfiguration(t.Context(), &empty.Empty{})
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package commit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -33,7 +32,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
|
||||
service, _ := newServiceWithMocks(t)
|
||||
request := &apiclient.CommitHydratedManifestsRequest{}
|
||||
_, err := service.CommitHydratedManifests(context.Background(), request)
|
||||
_, err := service.CommitHydratedManifests(t.Context(), request)
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, "repo is required")
|
||||
})
|
||||
|
|
@ -45,7 +44,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
request := &apiclient.CommitHydratedManifestsRequest{
|
||||
Repo: &v1alpha1.Repository{},
|
||||
}
|
||||
_, err := service.CommitHydratedManifests(context.Background(), request)
|
||||
_, err := service.CommitHydratedManifests(t.Context(), request)
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, "repo URL is required")
|
||||
})
|
||||
|
|
@ -59,7 +58,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
Repo: "https://github.com/argoproj/argocd-example-apps.git",
|
||||
},
|
||||
}
|
||||
_, err := service.CommitHydratedManifests(context.Background(), request)
|
||||
_, err := service.CommitHydratedManifests(t.Context(), request)
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, "target branch is required")
|
||||
})
|
||||
|
|
@ -74,7 +73,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
},
|
||||
TargetBranch: "main",
|
||||
}
|
||||
_, err := service.CommitHydratedManifests(context.Background(), request)
|
||||
_, err := service.CommitHydratedManifests(t.Context(), request)
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, "sync branch is required")
|
||||
})
|
||||
|
|
@ -85,7 +84,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
service, mockRepoClientFactory := newServiceWithMocks(t)
|
||||
mockRepoClientFactory.On("NewClient", mock.Anything, mock.Anything).Return(nil, assert.AnError).Once()
|
||||
|
||||
_, err := service.CommitHydratedManifests(context.Background(), validRequest)
|
||||
_, err := service.CommitHydratedManifests(t.Context(), validRequest)
|
||||
require.Error(t, err)
|
||||
assert.ErrorIs(t, err, assert.AnError)
|
||||
})
|
||||
|
|
@ -105,7 +104,7 @@ func Test_CommitHydratedManifests(t *testing.T) {
|
|||
mockGitClient.On("CommitSHA").Return("it-worked!", nil).Once()
|
||||
mockRepoClientFactory.On("NewClient", mock.Anything, mock.Anything).Return(mockGitClient, nil).Once()
|
||||
|
||||
resp, err := service.CommitHydratedManifests(context.Background(), validRequest)
|
||||
resp, err := service.CommitHydratedManifests(t.Context(), validRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
assert.Equal(t, "it-worked!", resp.HydratedSha)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
|
@ -90,7 +89,7 @@ func TestSetOptionalRedisPasswordFromKubeConfig(t *testing.T) {
|
|||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
ctx = t.Context()
|
||||
kubeClient = kubefake.NewClientset()
|
||||
redisOptions = &redis.Options{}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -595,7 +595,7 @@ func TestAutoSync(t *testing.T) {
|
|||
}
|
||||
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(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app.Operation)
|
||||
assert.NotNil(t, app.Operation.Sync)
|
||||
|
|
@ -616,7 +616,7 @@ func TestMultiSourceSelfHeal(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook-1", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -632,7 +632,7 @@ func TestMultiSourceSelfHeal(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook-1", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -675,7 +675,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -690,7 +690,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -706,7 +706,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -723,7 +723,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -749,7 +749,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
|
||||
assert.NotNil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -765,7 +765,7 @@ func TestSkipAutoSync(t *testing.T) {
|
|||
{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync, RequiresPruning: true},
|
||||
}, true)
|
||||
assert.Nil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
})
|
||||
|
|
@ -801,7 +801,7 @@ func TestAutoSyncIndicateError(t *testing.T) {
|
|||
}
|
||||
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
|
||||
assert.NotNil(t, cond)
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, app.Operation)
|
||||
}
|
||||
|
|
@ -844,7 +844,7 @@ func TestAutoSyncParameterOverrides(t *testing.T) {
|
|||
}
|
||||
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(context.Background(), "my-app", metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(t.Context(), "my-app", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app.Operation)
|
||||
}
|
||||
|
|
@ -2332,7 +2332,7 @@ func TestAddControllerNamespace(t *testing.T) {
|
|||
|
||||
ctrl.processAppRefreshQueueItem()
|
||||
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(ctrl.namespace).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(ctrl.namespace).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace)
|
||||
})
|
||||
|
|
@ -2351,7 +2351,7 @@ func TestAddControllerNamespace(t *testing.T) {
|
|||
|
||||
ctrl.processAppRefreshQueueItem()
|
||||
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(appNamespace).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(appNamespace).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.FakeArgoCDNamespace, updatedApp.Status.ControllerNamespace)
|
||||
})
|
||||
|
|
@ -2674,7 +2674,7 @@ func TestSyncTimeout(t *testing.T) {
|
|||
}
|
||||
ctrl.processRequestedAppOperation(app)
|
||||
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.ObjectMeta.Namespace).Get(context.Background(), app.ObjectMeta.Name, metav1.GetOptions{})
|
||||
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.ObjectMeta.Namespace).Get(t.Context(), app.ObjectMeta.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expectedPhase, app.Status.OperationState.Phase)
|
||||
require.Equal(t, tc.expectedMessage, app.Status.OperationState.Message)
|
||||
|
|
|
|||
3
controller/cache/cache_test.go
vendored
3
controller/cache/cache_test.go
vendored
|
|
@ -1,7 +1,6 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/url"
|
||||
|
|
@ -142,7 +141,7 @@ func TestHandleDeleteEvent_CacheDeadlock(t *testing.T) {
|
|||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetApplicationControllerReplicas").Return(1)
|
||||
fakeClient := fake.NewClientset()
|
||||
settingsMgr := argosettings.NewSettingsManager(context.TODO(), fakeClient, "argocd")
|
||||
settingsMgr := argosettings.NewSettingsManager(t.Context(), fakeClient, "argocd")
|
||||
liveStateCacheLock := sync.RWMutex{}
|
||||
gitopsEngineClusterCache := &mocks.ClusterCache{}
|
||||
clustersCache := liveStateCache{
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ func TestClusterSecretUpdater(t *testing.T) {
|
|||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
appclientset := appsfake.NewSimpleClientset()
|
||||
appInformer := appinformers.NewApplicationInformer(appclientset, "", time.Minute, cache.Indexers{})
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
argoDB := db.NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
appCache := appstate.NewCache(cacheutil.NewCache(cacheutil.NewInMemoryCache(time.Minute)), time.Minute)
|
||||
|
|
@ -90,7 +90,7 @@ func TestClusterSecretUpdater(t *testing.T) {
|
|||
lister := applisters.NewApplicationLister(appInformer.GetIndexer()).Applications(fakeNamespace)
|
||||
updater := NewClusterInfoUpdater(nil, argoDB, lister, appCache, nil, nil, fakeNamespace)
|
||||
|
||||
err = updater.updateClusterInfo(context.Background(), *cluster, info)
|
||||
err = updater.updateClusterInfo(t.Context(), *cluster, info)
|
||||
require.NoError(t, err, "Invoking updateClusterInfo failed.")
|
||||
|
||||
var clusterInfo v1alpha1.ClusterInfo
|
||||
|
|
@ -185,7 +185,7 @@ func TestUpdateClusterLabels(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.wantErr(t, updateClusterLabels(context.Background(), tt.clusterInfo, tt.cluster, tt.updateCluster), fmt.Sprintf("updateClusterLabels(%v, %v, %v)", context.Background(), tt.clusterInfo, tt.cluster))
|
||||
tt.wantErr(t, updateClusterLabels(t.Context(), tt.clusterInfo, tt.cluster, tt.updateCluster), fmt.Sprintf("updateClusterLabels(%v, %v, %v)", t.Context(), tt.clusterInfo, tt.cluster))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ func runTest(t *testing.T, cfg TestMetricServerConfig) {
|
|||
|
||||
if len(cfg.ClustersInfo) > 0 {
|
||||
ci := &fakeClusterInfo{clustersInfo: cfg.ClustersInfo}
|
||||
collector := NewClusterCollector(context.Background(), ci, cfg.ClusterLister, cfg.ClusterLabels)
|
||||
collector := NewClusterCollector(t.Context(), ci, cfg.ClusterLister, cfg.ClusterLabels)
|
||||
metricsServ.registry.MustRegister(collector)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package sharding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -817,7 +816,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
objects := append([]runtime.Object{}, deployment, deploymentMultiReplicas)
|
||||
kubeclientset := kubefake.NewSimpleClientset(objects...)
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd", settings.WithRepoOrClusterChangedHandler(func() {
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, "argocd", settings.WithRepoOrClusterChangedHandler(func() {
|
||||
}))
|
||||
|
||||
testCases := []struct {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
|
@ -54,7 +53,7 @@ func TestPersistRevisionHistory(t *testing.T) {
|
|||
// Ensure we record spec.source into sync result
|
||||
assert.Equal(t, app.Spec.GetSource(), opState.SyncResult.Source)
|
||||
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, updatedApp.Status.History, 1)
|
||||
assert.Equal(t, app.Spec.GetSource(), updatedApp.Status.History[0].Source)
|
||||
|
|
@ -143,7 +142,7 @@ func TestPersistRevisionHistoryRollback(t *testing.T) {
|
|||
// Ensure we record opState's source into sync result
|
||||
assert.Equal(t, source, opState.SyncResult.Source)
|
||||
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(app.Namespace).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, updatedApp.Status.History, 1)
|
||||
assert.Equal(t, source, updatedApp.Status.History[0].Source)
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -1,6 +1,6 @@
|
|||
module github.com/argoproj/argo-cd/v3
|
||||
|
||||
go 1.23.5
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.20.0
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ func TestInit(t *testing.T) {
|
|||
|
||||
assert.NotNil(t, nc)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err = nc.Init(ctx)
|
||||
|
|
@ -160,7 +160,7 @@ func TestInitTimeout(t *testing.T) {
|
|||
assert.NotNil(t, nc)
|
||||
|
||||
// Use a short timeout to simulate a timeout during cache synchronization
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), 1*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
err = nc.Init(ctx)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -105,8 +105,8 @@ func projTokenContext(ctx context.Context) context.Context {
|
|||
}
|
||||
|
||||
func TestUpdatePassword(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background())
|
||||
ctx := adminContext(context.Background())
|
||||
accountServer, sessionServer := newTestAccountServer(t, t.Context())
|
||||
ctx := adminContext(t.Context())
|
||||
var err error
|
||||
|
||||
// ensure password is not allowed to be updated if given bad password
|
||||
|
|
@ -141,10 +141,10 @@ func TestUpdatePassword(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdatePassword_AdminUpdatesAnotherUser(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, t.Context(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "anotherUser"})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -159,46 +159,46 @@ func TestUpdatePassword_DoesNotHavePermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("LocalAccountUpdatesAnotherAccount", func(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServerExt(t, t.Context(), enforcer, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "anotherUser"})
|
||||
assert.ErrorContains(t, err, "permission denied")
|
||||
})
|
||||
|
||||
t.Run("SSOAccountWithTheSameName", func(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer)
|
||||
ctx := ssoAdminContext(context.Background(), time.Now())
|
||||
accountServer, _ := newTestAccountServerExt(t, t.Context(), enforcer)
|
||||
ctx := ssoAdminContext(t.Context(), time.Now())
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "admin"})
|
||||
assert.ErrorContains(t, err, "permission denied")
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdatePassword_ProjectToken(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, t.Context(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := projTokenContext(context.Background())
|
||||
ctx := projTokenContext(t.Context())
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword"})
|
||||
assert.ErrorContains(t, err, "password can only be changed for local users")
|
||||
}
|
||||
|
||||
func TestUpdatePassword_OldSSOToken(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, t.Context(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := ssoAdminContext(context.Background(), time.Now().Add(-2*common.ChangePasswordSSOTokenMaxAge))
|
||||
ctx := ssoAdminContext(t.Context(), time.Now().Add(-2*common.ChangePasswordSSOTokenMaxAge))
|
||||
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "anotherUser"})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestUpdatePassword_SSOUserUpdatesAnotherUser(t *testing.T) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, context.Background(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, sessionServer := newTestAccountServer(t, t.Context(), func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.anotherUser"] = "login"
|
||||
})
|
||||
ctx := ssoAdminContext(context.Background(), time.Now())
|
||||
ctx := ssoAdminContext(t.Context(), time.Now())
|
||||
|
||||
_, err := accountServer.UpdatePassword(ctx, &account.UpdatePasswordRequest{CurrentPassword: "oldpassword", NewPassword: "newpassword", Name: "anotherUser"})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -208,7 +208,7 @@ func TestUpdatePassword_SSOUserUpdatesAnotherUser(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListAccounts_NoAccountsConfigured(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
|
||||
accountServer, _ := newTestAccountServer(t, ctx)
|
||||
resp, err := accountServer.ListAccounts(ctx, &account.ListAccountRequest{})
|
||||
|
|
@ -217,7 +217,7 @@ func TestListAccounts_NoAccountsConfigured(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListAccounts_AccountsAreConfigured(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
cm.Data["accounts.account2"] = "login, apiKey"
|
||||
|
|
@ -235,7 +235,7 @@ func TestListAccounts_AccountsAreConfigured(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
|
@ -255,7 +255,7 @@ func TestGetAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateToken_SuccessfullyCreated(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
|
@ -270,7 +270,7 @@ func TestCreateToken_SuccessfullyCreated(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateToken_DoesNotHaveCapability(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "login"
|
||||
})
|
||||
|
|
@ -280,7 +280,7 @@ func TestCreateToken_DoesNotHaveCapability(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCreateToken_UserSpecifiedID(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
})
|
||||
|
|
@ -294,7 +294,7 @@ func TestCreateToken_UserSpecifiedID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeleteToken_SuccessfullyRemoved(t *testing.T) {
|
||||
ctx := adminContext(context.Background())
|
||||
ctx := adminContext(t.Context())
|
||||
accountServer, _ := newTestAccountServer(t, ctx, func(cm *corev1.ConfigMap, secret *corev1.Secret) {
|
||||
cm.Data["accounts.account1"] = "apiKey"
|
||||
secret.Data["accounts.account1.tokens"] = []byte(`[{"id":"123","iat":1583789194,"exp":1583789194}]`)
|
||||
|
|
@ -310,10 +310,10 @@ func TestDeleteToken_SuccessfullyRemoved(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCanI_GetLogsAllow(t *testing.T) {
|
||||
accountServer, _ := newTestAccountServer(t, context.Background(), func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServer(t, t.Context(), func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
})
|
||||
|
||||
ctx := projTokenContext(context.Background())
|
||||
ctx := projTokenContext(t.Context())
|
||||
resp, err := accountServer.CanI(ctx, &account.CanIRequest{Resource: "logs", Action: "get", Subresource: ""})
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, "yes", resp.Value)
|
||||
|
|
@ -324,10 +324,10 @@ func TestCanI_GetLogsDeny(t *testing.T) {
|
|||
return false
|
||||
}
|
||||
|
||||
accountServer, _ := newTestAccountServerExt(t, context.Background(), enforcer, func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
accountServer, _ := newTestAccountServerExt(t, t.Context(), enforcer, func(_ *corev1.ConfigMap, _ *corev1.Secret) {
|
||||
})
|
||||
|
||||
ctx := projTokenContext(context.Background())
|
||||
ctx := projTokenContext(t.Context())
|
||||
resp, err := accountServer.CanI(ctx, &account.CanIRequest{Resource: "logs", Action: "get", Subresource: "*/*"})
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, "no", resp.Value)
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ func newTestAppServerWithEnforcerConfigure(t *testing.T, f func(*rbac.Enforcer),
|
|||
"server.secretkey": []byte("test"),
|
||||
},
|
||||
})
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(ctx, kubeclientset, testNamespace), kubeclientset)
|
||||
_, err := db.CreateRepository(ctx, fakeRepo())
|
||||
require.NoError(t, err)
|
||||
|
|
@ -349,7 +349,7 @@ func newTestAppServerWithEnforcerConfigureWithBenchmark(b *testing.B, f func(*rb
|
|||
"server.secretkey": []byte("test"),
|
||||
},
|
||||
})
|
||||
ctx := context.Background()
|
||||
ctx := b.Context()
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(ctx, kubeclientset, testNamespace), kubeclientset)
|
||||
_, err := db.CreateRepository(ctx, fakeRepo())
|
||||
require.NoError(b, err)
|
||||
|
|
@ -782,7 +782,7 @@ func TestNoAppEnumeration(t *testing.T) {
|
|||
testDeployment := kube.MustToUnstructured(&deployment)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(t, f, map[string]string{}, testApp, testHelmApp, testAppMulti, testDeployment)
|
||||
|
||||
noRoleCtx := context.Background()
|
||||
noRoleCtx := t.Context()
|
||||
//nolint:staticcheck
|
||||
adminCtx := context.WithValue(noRoleCtx, "claims", &jwt.MapClaims{"groups": []string{"admin"}})
|
||||
|
||||
|
|
@ -1082,11 +1082,11 @@ func TestNoAppEnumeration(t *testing.T) {
|
|||
func setSyncRunningOperationState(t *testing.T, appServer *Server) {
|
||||
t.Helper()
|
||||
appIf := appServer.appclientset.ArgoprojV1alpha1().Applications("default")
|
||||
app, err := appIf.Get(context.Background(), "test", metav1.GetOptions{})
|
||||
app, err := appIf.Get(t.Context(), "test", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
// This sets the status that would be set by the controller usually.
|
||||
app.Status.OperationState = &v1alpha1.OperationState{Phase: synccommon.OperationRunning, Operation: v1alpha1.Operation{Sync: &v1alpha1.SyncOperation{}}}
|
||||
_, err = appIf.Update(context.Background(), app, metav1.UpdateOptions{})
|
||||
_, err = appIf.Update(t.Context(), app, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -1094,11 +1094,11 @@ func setSyncRunningOperationState(t *testing.T, appServer *Server) {
|
|||
func unsetSyncRunningOperationState(t *testing.T, appServer *Server) {
|
||||
t.Helper()
|
||||
appIf := appServer.appclientset.ArgoprojV1alpha1().Applications("default")
|
||||
app, err := appIf.Get(context.Background(), "test", metav1.GetOptions{})
|
||||
app, err := appIf.Get(t.Context(), "test", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
app.Operation = nil
|
||||
app.Status.OperationState = nil
|
||||
_, err = appIf.Update(context.Background(), app, metav1.UpdateOptions{})
|
||||
_, err = appIf.Update(t.Context(), app, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -1185,7 +1185,7 @@ func testListAppsWithLabels(t *testing.T, appQuery application.ApplicationQuery,
|
|||
for _, validTest := range validTests {
|
||||
t.Run(validTest.testName, func(t *testing.T) {
|
||||
appQuery.Selector = &validTest.label
|
||||
res, err := appServer.List(context.Background(), &appQuery)
|
||||
res, err := appServer.List(t.Context(), &appQuery)
|
||||
require.NoError(t, err)
|
||||
apps := []string{}
|
||||
for i := range res.Items {
|
||||
|
|
@ -1215,7 +1215,7 @@ func testListAppsWithLabels(t *testing.T, appQuery application.ApplicationQuery,
|
|||
for _, invalidTest := range invalidTests {
|
||||
t.Run(invalidTest.testName, func(t *testing.T) {
|
||||
appQuery.Selector = &invalidTest.label
|
||||
_, err := appServer.List(context.Background(), &appQuery)
|
||||
_, err := appServer.List(t.Context(), &appQuery)
|
||||
assert.ErrorContains(t, err, invalidTest.errorMesage)
|
||||
})
|
||||
}
|
||||
|
|
@ -1235,14 +1235,14 @@ func TestListAppWithProjects(t *testing.T) {
|
|||
|
||||
t.Run("List all apps", func(t *testing.T) {
|
||||
appQuery := application.ApplicationQuery{}
|
||||
appList, err := appServer.List(context.Background(), &appQuery)
|
||||
appList, err := appServer.List(t.Context(), &appQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, appList.Items, 3)
|
||||
})
|
||||
|
||||
t.Run("List apps with projects filter set", func(t *testing.T) {
|
||||
appQuery := application.ApplicationQuery{Projects: []string{"test-project1"}}
|
||||
appList, err := appServer.List(context.Background(), &appQuery)
|
||||
appList, err := appServer.List(t.Context(), &appQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, appList.Items, 1)
|
||||
for _, app := range appList.Items {
|
||||
|
|
@ -1252,7 +1252,7 @@ func TestListAppWithProjects(t *testing.T) {
|
|||
|
||||
t.Run("List apps with project filter set (legacy field)", func(t *testing.T) {
|
||||
appQuery := application.ApplicationQuery{Project: []string{"test-project1"}}
|
||||
appList, err := appServer.List(context.Background(), &appQuery)
|
||||
appList, err := appServer.List(t.Context(), &appQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, appList.Items, 1)
|
||||
for _, app := range appList.Items {
|
||||
|
|
@ -1263,7 +1263,7 @@ func TestListAppWithProjects(t *testing.T) {
|
|||
t.Run("List apps with both projects and project filter set", func(t *testing.T) {
|
||||
// If the older field is present, we should use it instead of the newer field.
|
||||
appQuery := application.ApplicationQuery{Project: []string{"test-project1"}, Projects: []string{"test-project2"}}
|
||||
appList, err := appServer.List(context.Background(), &appQuery)
|
||||
appList, err := appServer.List(t.Context(), &appQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, appList.Items, 1)
|
||||
for _, app := range appList.Items {
|
||||
|
|
@ -1281,7 +1281,7 @@ func TestListApps(t *testing.T) {
|
|||
app.Name = "def"
|
||||
}))
|
||||
|
||||
res, err := appServer.List(context.Background(), &application.ApplicationQuery{})
|
||||
res, err := appServer.List(t.Context(), &application.ApplicationQuery{})
|
||||
require.NoError(t, err)
|
||||
var names []string
|
||||
for i := range res.Items {
|
||||
|
|
@ -1292,7 +1292,7 @@ func TestListApps(t *testing.T) {
|
|||
|
||||
func TestCoupleAppsListApps(t *testing.T) {
|
||||
var objects []runtime.Object
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
var groups []string
|
||||
for i := 0; i < 50; i++ {
|
||||
|
|
@ -1355,7 +1355,7 @@ func BenchmarkListMuchApps(b *testing.B) {
|
|||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
_, err := appServer.List(context.Background(), &application.ApplicationQuery{})
|
||||
_, err := appServer.List(b.Context(), &application.ApplicationQuery{})
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1373,7 +1373,7 @@ func BenchmarkListSomeApps(b *testing.B) {
|
|||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
_, err := appServer.List(context.Background(), &application.ApplicationQuery{})
|
||||
_, err := appServer.List(b.Context(), &application.ApplicationQuery{})
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1391,7 +1391,7 @@ func BenchmarkListFewApps(b *testing.B) {
|
|||
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
_, err := appServer.List(context.Background(), &application.ApplicationQuery{})
|
||||
_, err := appServer.List(b.Context(), &application.ApplicationQuery{})
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1414,7 +1414,7 @@ func BenchmarkListMuchAppsWithName(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
app := &application.ApplicationQuery{Name: strToPtr("test-app000099")}
|
||||
_, err := appServer.List(context.Background(), app)
|
||||
_, err := appServer.List(b.Context(), app)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1435,7 +1435,7 @@ func BenchmarkListMuchAppsWithProjects(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
app := &application.ApplicationQuery{Project: []string{"test-project1", "test-project2"}}
|
||||
_, err := appServer.List(context.Background(), app)
|
||||
_, err := appServer.List(b.Context(), app)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1455,7 +1455,7 @@ func BenchmarkListMuchAppsWithRepo(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
app := &application.ApplicationQuery{Repo: strToPtr("https://some-fake-source")}
|
||||
_, err := appServer.List(context.Background(), app)
|
||||
_, err := appServer.List(b.Context(), app)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1469,7 +1469,7 @@ func TestCreateApp(t *testing.T) {
|
|||
createReq := application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
}
|
||||
app, err := appServer.Create(context.Background(), &createReq)
|
||||
app, err := appServer.Create(t.Context(), &createReq)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Spec)
|
||||
|
|
@ -1482,7 +1482,7 @@ func TestCreateAppWithDestName(t *testing.T) {
|
|||
createReq := application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
}
|
||||
app, err := appServer.Create(context.Background(), &createReq)
|
||||
app, err := appServer.Create(t.Context(), &createReq)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, app)
|
||||
}
|
||||
|
|
@ -1502,7 +1502,7 @@ func TestCreateAppWithOperation(t *testing.T) {
|
|||
createReq := application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
}
|
||||
app, err := appServer.Create(context.Background(), &createReq)
|
||||
app, err := appServer.Create(t.Context(), &createReq)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, app)
|
||||
assert.Nil(t, app.Operation)
|
||||
|
|
@ -1512,7 +1512,7 @@ func TestUpdateApp(t *testing.T) {
|
|||
testApp := newTestApp()
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
testApp.Spec.Project = ""
|
||||
app, err := appServer.Update(context.Background(), &application.ApplicationUpdateRequest{
|
||||
app, err := appServer.Update(t.Context(), &application.ApplicationUpdateRequest{
|
||||
Application: testApp,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1523,19 +1523,19 @@ func TestUpdateAppSpec(t *testing.T) {
|
|||
testApp := newTestApp()
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
testApp.Spec.Project = ""
|
||||
spec, err := appServer.UpdateSpec(context.Background(), &application.ApplicationUpdateSpecRequest{
|
||||
spec, err := appServer.UpdateSpec(t.Context(), &application.ApplicationUpdateSpecRequest{
|
||||
Name: &testApp.Name,
|
||||
Spec: &testApp.Spec,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "default", spec.Project)
|
||||
app, err := appServer.Get(context.Background(), &application.ApplicationQuery{Name: &testApp.Name})
|
||||
app, err := appServer.Get(t.Context(), &application.ApplicationQuery{Name: &testApp.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "default", app.Spec.Project)
|
||||
}
|
||||
|
||||
func TestDeleteApp(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
appServer := newTestAppServer(t)
|
||||
createReq := application.ApplicationCreateRequest{
|
||||
Application: newTestApp(),
|
||||
|
|
@ -1625,7 +1625,7 @@ func TestDeleteApp(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeleteResourcesRBAC(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(ctx, "claims", &jwt.RegisteredClaims{Subject: "test-user"})
|
||||
testApp := newTestApp()
|
||||
|
|
@ -1718,7 +1718,7 @@ p, test-user, applications, delete/fake.io/PodTest/*, default/test-app, deny
|
|||
}
|
||||
|
||||
func TestPatchResourcesRBAC(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(ctx, "claims", &jwt.RegisteredClaims{Subject: "test-user"})
|
||||
testApp := newTestApp()
|
||||
|
|
@ -1811,7 +1811,7 @@ p, test-user, applications, update/fake.io/PodTest/*, default/test-app, deny
|
|||
}
|
||||
|
||||
func TestSyncAndTerminate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
appServer := newTestAppServer(t)
|
||||
testApp := newTestApp()
|
||||
testApp.Spec.Source.RepoURL = "https://github.com/argoproj/argo-cd.git"
|
||||
|
|
@ -1825,7 +1825,7 @@ func TestSyncAndTerminate(t *testing.T) {
|
|||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Operation)
|
||||
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(context.Background(), metav1.ListOptions{})
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
event := events.Items[1]
|
||||
|
||||
|
|
@ -1837,7 +1837,7 @@ func TestSyncAndTerminate(t *testing.T) {
|
|||
Phase: synccommon.OperationRunning,
|
||||
StartedAt: metav1.NewTime(time.Now()),
|
||||
}
|
||||
_, err = appServer.appclientset.ArgoprojV1alpha1().Applications(appServer.ns).Update(context.Background(), app, metav1.UpdateOptions{})
|
||||
_, err = appServer.appclientset.ArgoprojV1alpha1().Applications(appServer.ns).Update(t.Context(), app, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := appServer.TerminateOperation(ctx, &application.OperationTerminateRequest{Name: &app.Name})
|
||||
|
|
@ -1851,7 +1851,7 @@ func TestSyncAndTerminate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSyncHelm(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
appServer := newTestAppServer(t)
|
||||
testApp := newTestApp()
|
||||
testApp.Spec.Source.RepoURL = "https://argoproj.github.io/argo-helm"
|
||||
|
|
@ -1869,13 +1869,13 @@ func TestSyncHelm(t *testing.T) {
|
|||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Operation)
|
||||
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(context.Background(), metav1.ListOptions{})
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Unknown user initiated sync to 0.7.* (0.7.2)", events.Items[1].Message)
|
||||
}
|
||||
|
||||
func TestSyncGit(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
appServer := newTestAppServer(t)
|
||||
testApp := newTestApp()
|
||||
testApp.Spec.Source.RepoURL = "https://github.com/org/test"
|
||||
|
|
@ -1897,7 +1897,7 @@ func TestSyncGit(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.NotNil(t, app)
|
||||
assert.NotNil(t, app.Operation)
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(context.Background(), metav1.ListOptions{})
|
||||
events, err := appServer.kubeclientset.CoreV1().Events(appServer.ns).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Unknown user initiated sync locally", events.Items[1].Message)
|
||||
}
|
||||
|
|
@ -1911,7 +1911,7 @@ func TestRollbackApp(t *testing.T) {
|
|||
}}
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
||||
updatedApp, err := appServer.Rollback(context.Background(), &application.ApplicationRollbackRequest{
|
||||
updatedApp, err := appServer.Rollback(t.Context(), &application.ApplicationRollbackRequest{
|
||||
Name: &testApp.Name,
|
||||
Id: ptr.To(int64(1)),
|
||||
})
|
||||
|
|
@ -1926,7 +1926,7 @@ func TestRollbackApp(t *testing.T) {
|
|||
|
||||
func TestUpdateAppProject(t *testing.T) {
|
||||
testApp := newTestApp()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(ctx, "claims", &jwt.RegisteredClaims{Subject: "admin"})
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
|
@ -1990,7 +1990,7 @@ p, admin, applications, update, my-proj/test-app, allow
|
|||
|
||||
func TestAppJsonPatch(t *testing.T) {
|
||||
testApp := newTestAppWithAnnotations()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(ctx, "claims", &jwt.RegisteredClaims{Subject: "admin"})
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
|
@ -2015,7 +2015,7 @@ func TestAppJsonPatch(t *testing.T) {
|
|||
|
||||
func TestAppMergePatch(t *testing.T) {
|
||||
testApp := newTestApp()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(ctx, "claims", &jwt.RegisteredClaims{Subject: "admin"})
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
|
@ -2034,7 +2034,7 @@ func TestServer_GetApplicationSyncWindowsState(t *testing.T) {
|
|||
testApp.Spec.Project = "proj-maint"
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
||||
active, err := appServer.GetApplicationSyncWindows(context.Background(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
active, err := appServer.GetApplicationSyncWindows(t.Context(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, active.ActiveWindows, 1)
|
||||
})
|
||||
|
|
@ -2043,7 +2043,7 @@ func TestServer_GetApplicationSyncWindowsState(t *testing.T) {
|
|||
testApp.Spec.Project = "default"
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
||||
active, err := appServer.GetApplicationSyncWindows(context.Background(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
active, err := appServer.GetApplicationSyncWindows(t.Context(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, active.ActiveWindows)
|
||||
})
|
||||
|
|
@ -2052,7 +2052,7 @@ func TestServer_GetApplicationSyncWindowsState(t *testing.T) {
|
|||
testApp.Spec.Project = "none"
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
|
||||
active, err := appServer.GetApplicationSyncWindows(context.Background(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
active, err := appServer.GetApplicationSyncWindows(t.Context(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name})
|
||||
require.ErrorContains(t, err, "not exist")
|
||||
assert.Nil(t, active)
|
||||
})
|
||||
|
|
@ -2074,7 +2074,7 @@ func TestGetCachedAppState(t *testing.T) {
|
|||
return true, &v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}}}, nil
|
||||
})
|
||||
t.Run("NoError", func(t *testing.T) {
|
||||
err := appServer.getCachedAppState(context.Background(), testApp, func() error {
|
||||
err := appServer.getCachedAppState(t.Context(), testApp, func() error {
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -2105,7 +2105,7 @@ func TestGetCachedAppState(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
err := appServer.getCachedAppState(context.Background(), testApp, func() error {
|
||||
err := appServer.getCachedAppState(t.Context(), testApp, func() error {
|
||||
res := cache.ErrCacheMiss
|
||||
if retryCount == 1 {
|
||||
res = nil
|
||||
|
|
@ -2120,7 +2120,7 @@ func TestGetCachedAppState(t *testing.T) {
|
|||
|
||||
t.Run("NonCacheErrorDoesNotTriggerRefresh", func(t *testing.T) {
|
||||
randomError := stderrors.New("random error")
|
||||
err := appServer.getCachedAppState(context.Background(), testApp, func() error {
|
||||
err := appServer.getCachedAppState(t.Context(), testApp, func() error {
|
||||
return randomError
|
||||
})
|
||||
assert.Equal(t, randomError, err)
|
||||
|
|
@ -2306,7 +2306,7 @@ func createAppServerWithMaxLodLogs(t *testing.T, podNumber int, maxPodLogsToRend
|
|||
})
|
||||
runtimeObjects[podNumber] = testApp
|
||||
|
||||
noRoleCtx := context.Background()
|
||||
noRoleCtx := t.Context()
|
||||
//nolint:staticcheck
|
||||
adminCtx := context.WithValue(noRoleCtx, "claims", &jwt.MapClaims{"groups": []string{"admin"}})
|
||||
|
||||
|
|
@ -2335,7 +2335,7 @@ func refreshAnnotationRemover(t *testing.T, ctx context.Context, patched *int32,
|
|||
a.SetAnnotations(map[string]string{})
|
||||
a.SetResourceVersion("999")
|
||||
_, err = appServer.appclientset.ArgoprojV1alpha1().Applications(a.Namespace).Update(
|
||||
context.Background(), a, metav1.UpdateOptions{})
|
||||
t.Context(), a, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
atomic.AddInt32(patched, 1)
|
||||
ch <- ""
|
||||
|
|
@ -2345,7 +2345,7 @@ func refreshAnnotationRemover(t *testing.T, ctx context.Context, patched *int32,
|
|||
}
|
||||
|
||||
func TestGetAppRefresh_NormalRefresh(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
testApp := newTestApp()
|
||||
testApp.ObjectMeta.ResourceVersion = "1"
|
||||
|
|
@ -2357,7 +2357,7 @@ func TestGetAppRefresh_NormalRefresh(t *testing.T) {
|
|||
|
||||
go refreshAnnotationRemover(t, ctx, &patched, appServer, testApp.Name, ch)
|
||||
|
||||
_, err := appServer.Get(context.Background(), &application.ApplicationQuery{
|
||||
_, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: &testApp.Name,
|
||||
Refresh: ptr.To(string(v1alpha1.RefreshTypeNormal)),
|
||||
})
|
||||
|
|
@ -2372,7 +2372,7 @@ func TestGetAppRefresh_NormalRefresh(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetAppRefresh_HardRefresh(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
testApp := newTestApp()
|
||||
testApp.ObjectMeta.ResourceVersion = "1"
|
||||
|
|
@ -2392,7 +2392,7 @@ func TestGetAppRefresh_HardRefresh(t *testing.T) {
|
|||
|
||||
go refreshAnnotationRemover(t, ctx, &patched, appServer, testApp.Name, ch)
|
||||
|
||||
_, err := appServer.Get(context.Background(), &application.ApplicationQuery{
|
||||
_, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: &testApp.Name,
|
||||
Refresh: ptr.To(string(v1alpha1.RefreshTypeHard)),
|
||||
})
|
||||
|
|
@ -2537,7 +2537,7 @@ func TestRunNewStyleResourceAction(t *testing.T) {
|
|||
err := appStateCache.SetAppResourcesTree(testApp.Name, &v1alpha1.ApplicationTree{Nodes: nodes})
|
||||
require.NoError(t, err)
|
||||
|
||||
appResponse, runErr := appServer.RunResourceAction(context.Background(), &application.ResourceActionRunRequest{
|
||||
appResponse, runErr := appServer.RunResourceAction(t.Context(), &application.ResourceActionRunRequest{
|
||||
Name: &testApp.Name,
|
||||
Namespace: &namespace,
|
||||
Action: &action,
|
||||
|
|
@ -2563,7 +2563,7 @@ func TestRunNewStyleResourceAction(t *testing.T) {
|
|||
err := appStateCache.SetAppResourcesTree(testApp.Name, &v1alpha1.ApplicationTree{Nodes: nodes})
|
||||
require.NoError(t, err)
|
||||
|
||||
appResponse, runErr := appServer.RunResourceAction(context.Background(), &application.ResourceActionRunRequest{
|
||||
appResponse, runErr := appServer.RunResourceAction(t.Context(), &application.ResourceActionRunRequest{
|
||||
Name: &testApp.Name,
|
||||
Namespace: &namespace,
|
||||
Action: &action,
|
||||
|
|
@ -2634,7 +2634,7 @@ func TestRunOldStyleResourceAction(t *testing.T) {
|
|||
err := appStateCache.SetAppResourcesTree(testApp.Name, &v1alpha1.ApplicationTree{Nodes: nodes})
|
||||
require.NoError(t, err)
|
||||
|
||||
appResponse, runErr := appServer.RunResourceAction(context.Background(), &application.ResourceActionRunRequest{
|
||||
appResponse, runErr := appServer.RunResourceAction(t.Context(), &application.ResourceActionRunRequest{
|
||||
Name: &testApp.Name,
|
||||
Namespace: &namespace,
|
||||
Action: &action,
|
||||
|
|
@ -2709,7 +2709,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
t.Parallel()
|
||||
testApp := newTestApp()
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
apps, err := appServer.List(context.TODO(), &application.ApplicationQuery{})
|
||||
apps, err := appServer.List(t.Context(), &application.ApplicationQuery{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, apps.Items, 1)
|
||||
})
|
||||
|
|
@ -2719,7 +2719,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
testApp1 := newTestApp()
|
||||
testApp1.Namespace = "argocd-1"
|
||||
appServer := newTestAppServer(t, testApp1)
|
||||
apps, err := appServer.List(context.TODO(), &application.ApplicationQuery{})
|
||||
apps, err := appServer.List(t.Context(), &application.ApplicationQuery{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, apps.Items)
|
||||
})
|
||||
|
|
@ -2730,7 +2730,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
testApp2 := newTestApp()
|
||||
testApp2.Namespace = "argocd-1"
|
||||
appServer := newTestAppServer(t, testApp1, testApp2)
|
||||
apps, err := appServer.List(context.TODO(), &application.ApplicationQuery{AppNamespace: ptr.To("argocd-1")})
|
||||
apps, err := appServer.List(t.Context(), &application.ApplicationQuery{AppNamespace: ptr.To("argocd-1")})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, apps.Items)
|
||||
})
|
||||
|
|
@ -2741,7 +2741,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
testApp1.Namespace = "argocd-1"
|
||||
appServer := newTestAppServer(t, testApp1)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
apps, err := appServer.List(context.TODO(), &application.ApplicationQuery{})
|
||||
apps, err := appServer.List(t.Context(), &application.ApplicationQuery{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, apps.Items, 1)
|
||||
})
|
||||
|
|
@ -2750,7 +2750,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
t.Parallel()
|
||||
testApp := newTestApp()
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
app, err := appServer.Get(context.TODO(), &application.ApplicationQuery{
|
||||
app, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: ptr.To("test-app"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -2761,7 +2761,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
testApp := newTestApp()
|
||||
testApp.Namespace = "argocd-1"
|
||||
appServer := newTestAppServer(t, testApp)
|
||||
app, err := appServer.Get(context.TODO(), &application.ApplicationQuery{
|
||||
app, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: ptr.To("test-app"),
|
||||
AppNamespace: ptr.To("argocd-1"),
|
||||
})
|
||||
|
|
@ -2783,7 +2783,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
app, err := appServer.Get(context.TODO(), &application.ApplicationQuery{
|
||||
app, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: ptr.To("test-app"),
|
||||
AppNamespace: ptr.To("argocd-1"),
|
||||
})
|
||||
|
|
@ -2807,7 +2807,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
app, err := appServer.Get(context.TODO(), &application.ApplicationQuery{
|
||||
app, err := appServer.Get(t.Context(), &application.ApplicationQuery{
|
||||
Name: ptr.To("test-app"),
|
||||
AppNamespace: ptr.To("argocd-1"),
|
||||
})
|
||||
|
|
@ -2830,7 +2830,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
app, err := appServer.Create(context.TODO(), &application.ApplicationCreateRequest{
|
||||
app, err := appServer.Create(t.Context(), &application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -2854,7 +2854,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
app, err := appServer.Create(context.TODO(), &application.ApplicationCreateRequest{
|
||||
app, err := appServer.Create(t.Context(), &application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
})
|
||||
require.Error(t, err)
|
||||
|
|
@ -2877,7 +2877,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-2"}
|
||||
app, err := appServer.Create(context.TODO(), &application.ApplicationCreateRequest{
|
||||
app, err := appServer.Create(t.Context(), &application.ApplicationCreateRequest{
|
||||
Application: testApp,
|
||||
})
|
||||
require.Error(t, err)
|
||||
|
|
@ -2899,7 +2899,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
active, err := appServer.GetApplicationSyncWindows(context.TODO(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name, AppNamespace: &testApp.Namespace})
|
||||
active, err := appServer.GetApplicationSyncWindows(t.Context(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name, AppNamespace: &testApp.Namespace})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, active.ActiveWindows)
|
||||
})
|
||||
|
|
@ -2918,7 +2918,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
active, err := appServer.GetApplicationSyncWindows(context.TODO(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name, AppNamespace: &testApp.Namespace})
|
||||
active, err := appServer.GetApplicationSyncWindows(t.Context(), &application.ApplicationSyncWindowsQuery{Name: &testApp.Name, AppNamespace: &testApp.Namespace})
|
||||
require.Error(t, err)
|
||||
require.Nil(t, active)
|
||||
require.ErrorContains(t, err, "app is not allowed in project")
|
||||
|
|
@ -2938,7 +2938,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
links, err := appServer.ListLinks(context.TODO(), &application.ListAppLinksRequest{
|
||||
links, err := appServer.ListLinks(t.Context(), &application.ListAppLinksRequest{
|
||||
Name: ptr.To("test-app"),
|
||||
Namespace: ptr.To("argocd-1"),
|
||||
})
|
||||
|
|
@ -2961,7 +2961,7 @@ func TestAppNamespaceRestrictions(t *testing.T) {
|
|||
}
|
||||
appServer := newTestAppServer(t, testApp, otherNsProj)
|
||||
appServer.enabledNamespaces = []string{"argocd-1"}
|
||||
links, err := appServer.ListLinks(context.TODO(), &application.ListAppLinksRequest{
|
||||
links, err := appServer.ListLinks(t.Context(), &application.ListAppLinksRequest{
|
||||
Name: ptr.To("test-app"),
|
||||
Namespace: ptr.To("argocd-1"),
|
||||
})
|
||||
|
|
@ -3035,7 +3035,7 @@ func TestGetAmbiguousRevision_SingleSource(t *testing.T) {
|
|||
func TestServer_ResolveSourceRevisions_MultiSource(t *testing.T) {
|
||||
s := newTestAppServer(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
a := &v1alpha1.Application{
|
||||
Spec: v1alpha1.ApplicationSpec{
|
||||
Sources: []v1alpha1.ApplicationSource{
|
||||
|
|
@ -3063,7 +3063,7 @@ func TestServer_ResolveSourceRevisions_MultiSource(t *testing.T) {
|
|||
func TestServer_ResolveSourceRevisions_SingleSource(t *testing.T) {
|
||||
s := newTestAppServer(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
a := &v1alpha1.Application{
|
||||
Spec: v1alpha1.ApplicationSpec{
|
||||
Source: &v1alpha1.ApplicationSource{
|
||||
|
|
@ -3341,7 +3341,7 @@ func Test_RevisionMetadata(t *testing.T) {
|
|||
VersionId: tcc.versionId,
|
||||
}
|
||||
|
||||
_, err := s.RevisionMetadata(context.Background(), request)
|
||||
_, err := s.RevisionMetadata(t.Context(), request)
|
||||
if tcc.expectErrorContains != nil {
|
||||
require.ErrorContains(t, err, *tcc.expectErrorContains)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ func TestValidateWithAdminPermissions(t *testing.T) {
|
|||
ts.terminalOpts = &TerminalOptions{Enf: enf}
|
||||
ts.appRBACName = "test"
|
||||
//nolint:staticcheck
|
||||
ts.ctx = context.WithValue(context.Background(), "claims", &jwt.MapClaims{"groups": []string{"admin"}})
|
||||
ts.ctx = context.WithValue(t.Context(), "claims", &jwt.MapClaims{"groups": []string{"admin"}})
|
||||
_, err := ts.validatePermissions([]byte{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ func TestValidateWithoutPermissions(t *testing.T) {
|
|||
ts.terminalOpts = &TerminalOptions{Enf: enf}
|
||||
ts.appRBACName = "test"
|
||||
//nolint:staticcheck
|
||||
ts.ctx = context.WithValue(context.Background(), "claims", &jwt.MapClaims{"groups": []string{"test"}})
|
||||
ts.ctx = context.WithValue(t.Context(), "claims", &jwt.MapClaims{"groups": []string{"test"}})
|
||||
_, err := ts.validatePermissions([]byte{})
|
||||
require.Error(t, err)
|
||||
assert.EqualError(t, err, common.PermissionDeniedAPIError.Error())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package applicationset
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
|
|
@ -92,7 +91,7 @@ func newTestAppSetServerWithEnforcerConfigure(t *testing.T, f func(*rbac.Enforce
|
|||
"server.secretkey": []byte("test"),
|
||||
},
|
||||
})
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(ctx, kubeclientset, testNamespace), kubeclientset)
|
||||
_, err := db.CreateRepository(ctx, fakeRepo())
|
||||
require.NoError(t, err)
|
||||
|
|
@ -238,7 +237,7 @@ func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.Applicat
|
|||
for _, validTest := range validTests {
|
||||
t.Run(validTest.testName, func(t *testing.T) {
|
||||
appsetQuery.Selector = validTest.label
|
||||
res, err := appServer.List(context.Background(), &appsetQuery)
|
||||
res, err := appServer.List(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
apps := []string{}
|
||||
for i := range res.Items {
|
||||
|
|
@ -268,7 +267,7 @@ func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.Applicat
|
|||
for _, invalidTest := range invalidTests {
|
||||
t.Run(invalidTest.testName, func(t *testing.T) {
|
||||
appsetQuery.Selector = invalidTest.label
|
||||
_, err := appServer.List(context.Background(), &appsetQuery)
|
||||
_, err := appServer.List(t.Context(), &appsetQuery)
|
||||
assert.ErrorContains(t, err, invalidTest.errorMesage)
|
||||
})
|
||||
}
|
||||
|
|
@ -332,7 +331,7 @@ func TestListAppSetsWithoutNamespace(t *testing.T) {
|
|||
appSetServer.enabledNamespaces = []string{testNamespace}
|
||||
appsetQuery := applicationset.ApplicationSetListQuery{}
|
||||
|
||||
res, err := appSetServer.List(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.List(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, res.Items)
|
||||
}
|
||||
|
|
@ -348,7 +347,7 @@ func TestCreateAppSet(t *testing.T) {
|
|||
createReq := applicationset.ApplicationSetCreateRequest{
|
||||
Applicationset: testAppSet,
|
||||
}
|
||||
_, err := appServer.Create(context.Background(), &createReq)
|
||||
_, err := appServer.Create(t.Context(), &createReq)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +358,7 @@ func TestCreateAppSetTemplatedProject(t *testing.T) {
|
|||
createReq := applicationset.ApplicationSetCreateRequest{
|
||||
Applicationset: testAppSet,
|
||||
}
|
||||
_, err := appServer.Create(context.Background(), &createReq)
|
||||
_, err := appServer.Create(t.Context(), &createReq)
|
||||
assert.EqualError(t, err, "error validating ApplicationSets: the Argo CD API does not currently support creating ApplicationSets with templated `project` fields")
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +369,7 @@ func TestCreateAppSetWrongNamespace(t *testing.T) {
|
|||
createReq := applicationset.ApplicationSetCreateRequest{
|
||||
Applicationset: testAppSet,
|
||||
}
|
||||
_, err := appServer.Create(context.Background(), &createReq)
|
||||
_, err := appServer.Create(t.Context(), &createReq)
|
||||
|
||||
assert.EqualError(t, err, "namespace 'NOT-ALLOWED' is not permitted")
|
||||
}
|
||||
|
|
@ -390,7 +389,7 @@ func TestCreateAppSetDryRun(t *testing.T) {
|
|||
Applicationset: testAppSet,
|
||||
DryRun: true,
|
||||
}
|
||||
result, err := appServer.Create(context.Background(), &createReq)
|
||||
result, err := appServer.Create(t.Context(), &createReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, result.Status.Resources, 2)
|
||||
|
|
@ -421,7 +420,7 @@ func TestCreateAppSetDryRunWithDuplicate(t *testing.T) {
|
|||
Applicationset: testAppSet,
|
||||
DryRun: true,
|
||||
}
|
||||
result, err := appServer.Create(context.Background(), &createReq)
|
||||
result, err := appServer.Create(t.Context(), &createReq)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, result.Status.Resources, 1)
|
||||
|
|
@ -447,7 +446,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1"}
|
||||
|
||||
res, err := appSetServer.Get(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.Get(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "AppSet1", res.Name)
|
||||
})
|
||||
|
|
@ -457,7 +456,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
res, err := appSetServer.Get(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.Get(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "AppSet1", res.Name)
|
||||
})
|
||||
|
|
@ -467,7 +466,7 @@ func TestGetAppSet(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetGetQuery{Name: "AppSet1", AppsetNamespace: "NOT-ALLOWED"}
|
||||
|
||||
_, err := appSetServer.Get(context.Background(), &appsetQuery)
|
||||
_, err := appSetServer.Get(t.Context(), &appsetQuery)
|
||||
assert.EqualError(t, err, "namespace 'NOT-ALLOWED' is not permitted")
|
||||
})
|
||||
}
|
||||
|
|
@ -490,7 +489,7 @@ func TestDeleteAppSet(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1"}
|
||||
|
||||
res, err := appSetServer.Delete(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.Delete(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &applicationset.ApplicationSetResponse{}, res)
|
||||
})
|
||||
|
|
@ -500,7 +499,7 @@ func TestDeleteAppSet(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetDeleteRequest{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
res, err := appSetServer.Delete(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.Delete(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &applicationset.ApplicationSetResponse{}, res)
|
||||
})
|
||||
|
|
@ -530,7 +529,7 @@ func TestUpdateAppSet(t *testing.T) {
|
|||
t.Run("Update merge", func(t *testing.T) {
|
||||
appServer := newTestAppSetServer(t, appSet)
|
||||
|
||||
updated, err := appServer.updateAppSet(context.Background(), appSet, newAppSet, true)
|
||||
updated, err := appServer.updateAppSet(t.Context(), appSet, newAppSet, true)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]string{
|
||||
|
|
@ -546,7 +545,7 @@ func TestUpdateAppSet(t *testing.T) {
|
|||
t.Run("Update no merge", func(t *testing.T) {
|
||||
appServer := newTestAppSetServer(t, appSet)
|
||||
|
||||
updated, err := appServer.updateAppSet(context.Background(), appSet, newAppSet, false)
|
||||
updated, err := appServer.updateAppSet(t.Context(), appSet, newAppSet, false)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]string{
|
||||
|
|
@ -617,7 +616,7 @@ func TestResourceTree(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1"}
|
||||
|
||||
res, err := appSetServer.ResourceTree(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.ResourceTree(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedTree, res)
|
||||
})
|
||||
|
|
@ -627,7 +626,7 @@ func TestResourceTree(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1", AppsetNamespace: testNamespace}
|
||||
|
||||
res, err := appSetServer.ResourceTree(context.Background(), &appsetQuery)
|
||||
res, err := appSetServer.ResourceTree(t.Context(), &appsetQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedTree, res)
|
||||
})
|
||||
|
|
@ -637,7 +636,7 @@ func TestResourceTree(t *testing.T) {
|
|||
|
||||
appsetQuery := applicationset.ApplicationSetTreeQuery{Name: "AppSet1", AppsetNamespace: "NOT-ALLOWED"}
|
||||
|
||||
_, err := appSetServer.ResourceTree(context.Background(), &appsetQuery)
|
||||
_, err := appSetServer.ResourceTree(t.Context(), &appsetQuery)
|
||||
assert.EqualError(t, err, "namespace 'NOT-ALLOWED' is not permitted")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package badge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"net/http"
|
||||
|
|
@ -100,7 +99,7 @@ func testProject() *v1alpha1.AppProject {
|
|||
}
|
||||
|
||||
func TestHandlerFeatureIsEnabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -198,7 +197,7 @@ func TestHandlerFeatureProjectIsEnabled(t *testing.T) {
|
|||
argoCDCm.ObjectMeta.Namespace = tt.namespace
|
||||
argoCDSecret.ObjectMeta.Namespace = tt.namespace
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm, argoCDSecret), tt.namespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm, argoCDSecret), tt.namespace)
|
||||
objects := []runtime.Object{testProject()}
|
||||
for _, v := range tt.testApp {
|
||||
objects = append(objects, v)
|
||||
|
|
@ -225,7 +224,7 @@ func TestHandlerFeatureProjectIsEnabled(t *testing.T) {
|
|||
|
||||
func TestHandlerNamespacesIsEnabled(t *testing.T) {
|
||||
t.Run("Application in allowed namespace", func(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&namespace=argocd-test", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -246,7 +245,7 @@ func TestHandlerNamespacesIsEnabled(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Application in disallowed namespace", func(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&namespace=kube-system", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -263,7 +262,7 @@ func TestHandlerNamespacesIsEnabled(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Request with illegal namespace", func(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp2()), settingsMgr, "default", []string{"argocd-test"})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&namespace=kube()system", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -276,7 +275,7 @@ func TestHandlerNamespacesIsEnabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandlerFeatureIsEnabledKeepFullRevisionIsEnabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{""})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=true", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -297,7 +296,7 @@ func TestHandlerFeatureIsEnabledKeepFullRevisionIsEnabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandlerFeatureIsEnabledKeepFullRevisionIsDisabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=false", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -318,7 +317,7 @@ func TestHandlerFeatureIsEnabledKeepFullRevisionIsDisabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandlerFeatureIsEnabledKeepFullRevisionAndWidthIsEnabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp3()), settingsMgr, "argocd-test", []string{""})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true&keepFullRevision=true&width=500", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -392,7 +391,7 @@ func createApplicationsWithName(appCombo, projectName []string, namespace string
|
|||
}
|
||||
|
||||
func TestHandlerFeatureIsEnabledRevisionIsEnabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -416,7 +415,7 @@ func TestHandlerRevisionIsEnabledNoOperationState(t *testing.T) {
|
|||
app := testApp()
|
||||
app.Status.OperationState = nil
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -440,7 +439,7 @@ func TestHandlerRevisionIsEnabledShortCommitSHA(t *testing.T) {
|
|||
app := testApp()
|
||||
app.Status.OperationState.SyncResult.Revision = "abc"
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(app), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&revision=true", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -456,7 +455,7 @@ func TestHandlerFeatureIsDisabled(t *testing.T) {
|
|||
argoCDCmDisabled := argoCDCm()
|
||||
delete(argoCDCmDisabled.Data, "statusbadge.enabled")
|
||||
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewSimpleClientset(argoCDCmDisabled, argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCmDisabled, argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -477,7 +476,7 @@ func TestHandlerFeatureIsDisabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandlerApplicationNameInBadgeIsEnabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app&showAppName=true", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -504,7 +503,7 @@ func TestHandlerApplicationNameInBadgeIsEnabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHandlerApplicationNameInBadgeIsDisabled(t *testing.T) {
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), fake.NewSimpleClientset(argoCDCm(), argoCDSecret()), "default")
|
||||
handler := NewHandler(appclientset.NewSimpleClientset(testApp()), settingsMgr, "default", []string{})
|
||||
req, err := http.NewRequest(http.MethodGet, "/api/badge?name=test-app", nil)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ p, role:test, clusters, *, allowed-project/*, allow`)
|
|||
cc := c
|
||||
t.Run(cc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
out, err := server.Update(context.Background(), &cc.request)
|
||||
out, err := server.Update(t.Context(), &cc.request)
|
||||
require.Nil(t, out)
|
||||
assert.ErrorIs(t, err, common.PermissionDeniedAPIError)
|
||||
})
|
||||
|
|
@ -261,7 +261,7 @@ func TestGetCluster_UrlEncodedName(t *testing.T) {
|
|||
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
localCluster, err := server.Get(context.Background(), &cluster.ClusterQuery{
|
||||
localCluster, err := server.Get(t.Context(), &cluster.ClusterQuery{
|
||||
Id: &cluster.ClusterID{
|
||||
Type: "name_escaped",
|
||||
Value: "test%2fing",
|
||||
|
|
@ -291,7 +291,7 @@ func TestGetCluster_NameWithUrlEncodingButShouldNotBeUnescaped(t *testing.T) {
|
|||
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
localCluster, err := server.Get(context.Background(), &cluster.ClusterQuery{
|
||||
localCluster, err := server.Get(t.Context(), &cluster.ClusterQuery{
|
||||
Id: &cluster.ClusterID{
|
||||
Type: "name",
|
||||
Value: "test%2fing",
|
||||
|
|
@ -318,11 +318,11 @@ func TestGetCluster_CannotSetCADataAndInsecureTrue(t *testing.T) {
|
|||
},
|
||||
}
|
||||
clientset := getClientset(nil, testNamespace)
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
t.Run("Create Fails When CAData is Set and Insecure is True", func(t *testing.T) {
|
||||
_, err := server.Create(context.Background(), &cluster.ClusterCreateRequest{
|
||||
_, err := server.Create(t.Context(), &cluster.ClusterCreateRequest{
|
||||
Cluster: localCluster,
|
||||
})
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ func TestGetCluster_CannotSetCADataAndInsecureTrue(t *testing.T) {
|
|||
|
||||
localCluster.Config.TLSClientConfig.CAData = nil
|
||||
t.Run("Create Succeeds When CAData is nil and Insecure is True", func(t *testing.T) {
|
||||
_, err := server.Create(context.Background(), &cluster.ClusterCreateRequest{
|
||||
_, err := server.Create(t.Context(), &cluster.ClusterCreateRequest{
|
||||
Cluster: localCluster,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -363,7 +363,7 @@ func TestUpdateCluster_NoFieldsPaths(t *testing.T) {
|
|||
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
_, err := server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err := server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Name: "minikube",
|
||||
Namespaces: []string{"default", "kube-system"},
|
||||
|
|
@ -391,7 +391,7 @@ func TestUpdateCluster_FieldsPathSet(t *testing.T) {
|
|||
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
_, err := server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err := server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Server: "https://127.0.0.1",
|
||||
Shard: ptr.To(int64(1)),
|
||||
|
|
@ -408,7 +408,7 @@ func TestUpdateCluster_FieldsPathSet(t *testing.T) {
|
|||
labelEnv := map[string]string{
|
||||
"env": "qa",
|
||||
}
|
||||
_, err = server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err = server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Server: "https://127.0.0.1",
|
||||
Labels: labelEnv,
|
||||
|
|
@ -425,7 +425,7 @@ func TestUpdateCluster_FieldsPathSet(t *testing.T) {
|
|||
annotationEnv := map[string]string{
|
||||
"env": "qa",
|
||||
}
|
||||
_, err = server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err = server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Server: "https://127.0.0.1",
|
||||
Annotations: annotationEnv,
|
||||
|
|
@ -439,7 +439,7 @@ func TestUpdateCluster_FieldsPathSet(t *testing.T) {
|
|||
assert.Equal(t, []string{"default", "kube-system"}, updated.Namespaces)
|
||||
assert.Equal(t, updated.Annotations, annotationEnv)
|
||||
|
||||
_, err = server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err = server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Server: "https://127.0.0.1",
|
||||
Project: "new-project",
|
||||
|
|
@ -473,11 +473,11 @@ func TestDeleteClusterByName(t *testing.T) {
|
|||
"config": []byte("{}"),
|
||||
},
|
||||
})
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
t.Run("Delete Fails When Deleting by Unknown Name", func(t *testing.T) {
|
||||
_, err := server.Delete(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.Delete(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "foo",
|
||||
})
|
||||
|
||||
|
|
@ -485,12 +485,12 @@ func TestDeleteClusterByName(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Delete Succeeds When Deleting by Name", func(t *testing.T) {
|
||||
_, err := server.Delete(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.Delete(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "my-cluster-name",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.GetCluster(context.Background(), "https://my-cluster-server")
|
||||
_, err = db.GetCluster(t.Context(), "https://my-cluster-server")
|
||||
assert.EqualError(t, err, `rpc error: code = NotFound desc = cluster "https://my-cluster-server" not found`)
|
||||
})
|
||||
}
|
||||
|
|
@ -550,11 +550,11 @@ func TestRotateAuth(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := db.NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
t.Run("RotateAuth by Unknown Name", func(t *testing.T) {
|
||||
_, err := server.RotateAuth(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.RotateAuth(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "foo",
|
||||
})
|
||||
|
||||
|
|
@ -565,7 +565,7 @@ func TestRotateAuth(t *testing.T) {
|
|||
// demonstrate the proper mapping of cluster names/server to server info (i.e. my-cluster-name
|
||||
// results in https://my-cluster-name info being used and https://my-cluster-name results in https://my-cluster-name).
|
||||
t.Run("RotateAuth by Name - Error from no such host", func(t *testing.T) {
|
||||
_, err := server.RotateAuth(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.RotateAuth(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "my-cluster-name",
|
||||
})
|
||||
|
||||
|
|
@ -573,7 +573,7 @@ func TestRotateAuth(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("RotateAuth by Server - Error from no such host", func(t *testing.T) {
|
||||
_, err := server.RotateAuth(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.RotateAuth(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://my-cluster-name",
|
||||
})
|
||||
|
||||
|
|
@ -705,7 +705,7 @@ func TestListCluster(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got, err := s.List(context.Background(), tt.q)
|
||||
got, err := s.List(t.Context(), tt.q)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err, "Server.List()")
|
||||
} else {
|
||||
|
|
@ -735,7 +735,7 @@ func TestGetClusterAndVerifyAccess(t *testing.T) {
|
|||
db.On("ListClusters", mock.Anything).Return(&mockClusterList, nil)
|
||||
|
||||
server := NewServer(db, newNoopEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
localCluster, err := server.getClusterAndVerifyAccess(context.Background(), &cluster.ClusterQuery{
|
||||
localCluster, err := server.getClusterAndVerifyAccess(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "test/not-exists",
|
||||
}, rbac.ActionGet)
|
||||
|
||||
|
|
@ -761,7 +761,7 @@ func TestGetClusterAndVerifyAccess(t *testing.T) {
|
|||
db.On("ListClusters", mock.Anything).Return(&mockClusterList, nil)
|
||||
|
||||
server := NewServer(db, newEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
localCluster, err := server.getClusterAndVerifyAccess(context.Background(), &cluster.ClusterQuery{
|
||||
localCluster, err := server.getClusterAndVerifyAccess(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "test/ing",
|
||||
}, rbac.ActionGet)
|
||||
|
||||
|
|
@ -791,26 +791,26 @@ func TestNoClusterEnumeration(t *testing.T) {
|
|||
server := NewServer(db, newEnforcer(), newServerInMemoryCache(), &kubetest.MockKubectlCmd{})
|
||||
|
||||
t.Run("Get", func(t *testing.T) {
|
||||
_, err := server.Get(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.Get(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "cluster-not-exists",
|
||||
})
|
||||
require.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
||||
_, err = server.Get(context.Background(), &cluster.ClusterQuery{
|
||||
_, err = server.Get(t.Context(), &cluster.ClusterQuery{
|
||||
Name: "test/ing",
|
||||
})
|
||||
assert.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
})
|
||||
|
||||
t.Run("Update", func(t *testing.T) {
|
||||
_, err := server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err := server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Name: "cluster-not-exists",
|
||||
},
|
||||
})
|
||||
require.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
||||
_, err = server.Update(context.Background(), &cluster.ClusterUpdateRequest{
|
||||
_, err = server.Update(t.Context(), &cluster.ClusterUpdateRequest{
|
||||
Cluster: &v1alpha1.Cluster{
|
||||
Name: "test/ing",
|
||||
},
|
||||
|
|
@ -819,36 +819,36 @@ func TestNoClusterEnumeration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
_, err := server.Delete(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.Delete(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.2",
|
||||
})
|
||||
require.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
||||
_, err = server.Delete(context.Background(), &cluster.ClusterQuery{
|
||||
_, err = server.Delete(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.1",
|
||||
})
|
||||
assert.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
})
|
||||
|
||||
t.Run("RotateAuth", func(t *testing.T) {
|
||||
_, err := server.RotateAuth(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.RotateAuth(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.2",
|
||||
})
|
||||
require.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
||||
_, err = server.RotateAuth(context.Background(), &cluster.ClusterQuery{
|
||||
_, err = server.RotateAuth(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.1",
|
||||
})
|
||||
assert.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
})
|
||||
|
||||
t.Run("InvalidateCache", func(t *testing.T) {
|
||||
_, err := server.InvalidateCache(context.Background(), &cluster.ClusterQuery{
|
||||
_, err := server.InvalidateCache(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.2",
|
||||
})
|
||||
require.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
||||
_, err = server.InvalidateCache(context.Background(), &cluster.ClusterQuery{
|
||||
_, err = server.InvalidateCache(t.Context(), &cluster.ClusterQuery{
|
||||
Server: "https://127.0.0.1",
|
||||
})
|
||||
assert.ErrorIs(t, err, common.PermissionDeniedAPIError, "error message must be _only_ the permission error, to avoid leaking information about cluster existence")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package extension_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -137,7 +136,7 @@ func TestRegisterExtensions(t *testing.T) {
|
|||
settMock := &mocks.SettingsGetter{}
|
||||
|
||||
logger, _ := test.NewNullLogger()
|
||||
logEntry := logger.WithContext(context.Background())
|
||||
logEntry := logger.WithContext(t.Context())
|
||||
m := extension.NewManager(logEntry, "", settMock, nil, nil, nil, nil, nil)
|
||||
|
||||
return &fixture{
|
||||
|
|
@ -258,7 +257,7 @@ func TestCallExtension(t *testing.T) {
|
|||
dbMock.On("GetCluster", mock.Anything, mock.Anything).Return(&v1alpha1.Cluster{Server: "some-url", Name: "cluster1"}, nil)
|
||||
|
||||
logger, _ := test.NewNullLogger()
|
||||
logEntry := logger.WithContext(context.Background())
|
||||
logEntry := logger.WithContext(t.Context())
|
||||
m := extension.NewManager(logEntry, defaultServerNamespace, settMock, appMock, projMock, dbMock, rbacMock, userMock)
|
||||
m.AddMetricsRegistry(metricsMock)
|
||||
|
||||
|
|
@ -513,9 +512,9 @@ func TestCallExtension(t *testing.T) {
|
|||
req := newExtensionRequest(t, http.MethodGet, url)
|
||||
req.Header.Del(extension.HeaderArgoCDApplicationName)
|
||||
|
||||
req1 := req.Clone(context.Background())
|
||||
req1 := req.Clone(t.Context())
|
||||
req1.Header.Add(extension.HeaderArgoCDApplicationName, "ns1:app1")
|
||||
req2 := req.Clone(context.Background())
|
||||
req2 := req.Clone(t.Context())
|
||||
req2.Header.Add(extension.HeaderArgoCDApplicationName, "ns2:app2")
|
||||
|
||||
// when
|
||||
|
|
@ -692,7 +691,7 @@ func TestCallExtension(t *testing.T) {
|
|||
url := fmt.Sprintf("%s/extensions/%s/", ts.URL, extName)
|
||||
req := newExtensionRequest(t, http.MethodGet, url)
|
||||
req.Header.Del(extension.HeaderArgoCDApplicationName)
|
||||
req1 := req.Clone(context.Background())
|
||||
req1 := req.Clone(t.Context())
|
||||
req1.Header.Add(extension.HeaderArgoCDApplicationName, "ns1:app1")
|
||||
|
||||
// when
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package logout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -238,11 +237,11 @@ func TestHandlerConstructLogoutURL(t *testing.T) {
|
|||
},
|
||||
)
|
||||
|
||||
settingsManagerWithOIDCConfig := settings.NewSettingsManager(context.Background(), kubeClientWithOIDCConfig, "default")
|
||||
settingsManagerWithoutOIDCConfig := settings.NewSettingsManager(context.Background(), kubeClientWithoutOIDCConfig, "default")
|
||||
settingsManagerWithOIDCConfigButNoLogoutURL := settings.NewSettingsManager(context.Background(), kubeClientWithOIDCConfigButNoLogoutURL, "default")
|
||||
settingsManagerWithoutOIDCAndMultipleURLs := settings.NewSettingsManager(context.Background(), kubeClientWithoutOIDCAndMultipleURLs, "default")
|
||||
settingsManagerWithOIDCConfigButNoURL := settings.NewSettingsManager(context.Background(), kubeClientWithOIDCConfigButNoURL, "default")
|
||||
settingsManagerWithOIDCConfig := settings.NewSettingsManager(t.Context(), kubeClientWithOIDCConfig, "default")
|
||||
settingsManagerWithoutOIDCConfig := settings.NewSettingsManager(t.Context(), kubeClientWithoutOIDCConfig, "default")
|
||||
settingsManagerWithOIDCConfigButNoLogoutURL := settings.NewSettingsManager(t.Context(), kubeClientWithOIDCConfigButNoLogoutURL, "default")
|
||||
settingsManagerWithoutOIDCAndMultipleURLs := settings.NewSettingsManager(t.Context(), kubeClientWithoutOIDCAndMultipleURLs, "default")
|
||||
settingsManagerWithOIDCConfigButNoURL := settings.NewSettingsManager(t.Context(), kubeClientWithOIDCConfigButNoURL, "default")
|
||||
|
||||
sessionManager := session.NewSessionManager(settingsManagerWithOIDCConfig, test.NewFakeProjLister(), "", nil, session.NewUserStateStorage(nil))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -54,7 +53,7 @@ func TestNotificationServer(t *testing.T) {
|
|||
Data: map[string][]byte{},
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
secretInformer := k8s.NewSecretInformer(kubeclientset, testNamespace, "argocd-notifications-secret")
|
||||
configMapInformer := k8s.NewConfigMapInformer(kubeclientset, testNamespace, "argocd-notifications-cm")
|
||||
go secretInformer.Run(ctx.Done())
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func TestProjectServer(t *testing.T) {
|
|||
"server": []byte("https://server3"),
|
||||
},
|
||||
})
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, testNamespace)
|
||||
enforcer := newEnforcer(kubeclientset)
|
||||
existingProj := v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: testNamespace},
|
||||
|
|
@ -113,7 +113,7 @@ func TestProjectServer(t *testing.T) {
|
|||
|
||||
policyTemplate := "p, proj:%s:%s, applications, %s, %s/%s, %s"
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
fakeAppsClientset := apps.NewSimpleClientset()
|
||||
factory := informer.NewSharedInformerFactoryWithOptions(fakeAppsClientset, 0, informer.WithNamespace(""), informer.WithTweakListOptions(func(_ *metav1.ListOptions) {}))
|
||||
projInformer := factory.Argoproj().V1alpha1().AppProjects().Informer()
|
||||
|
|
@ -133,7 +133,7 @@ func TestProjectServer(t *testing.T) {
|
|||
err := projectServer.NormalizeProjs()
|
||||
require.NoError(t, err)
|
||||
|
||||
appList, err := projectServer.appclientset.ArgoprojV1alpha1().AppProjects(projectWithRole.Namespace).List(context.Background(), metav1.ListOptions{})
|
||||
appList, err := projectServer.appclientset.ArgoprojV1alpha1().AppProjects(projectWithRole.Namespace).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), appList.Items[0].Status.JWTTokensByRole[roleName].Items[0].IssuedAt)
|
||||
assert.ElementsMatch(t, appList.Items[0].Status.JWTTokensByRole[roleName].Items, appList.Items[0].Spec.Roles[0].JWTTokens)
|
||||
|
|
@ -148,7 +148,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.Destinations = nil
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
assert.Equal(t, status.Error(codes.PermissionDenied, "permission denied: clusters, update, https://server1"), err)
|
||||
})
|
||||
|
|
@ -162,7 +162,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.SourceRepos = nil
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
assert.Equal(t, status.Error(codes.PermissionDenied, "permission denied: repositories, update, https://github.com/argoproj/argo-cd.git"), err)
|
||||
})
|
||||
|
|
@ -176,7 +176,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.ClusterResourceWhitelist = []metav1.GroupKind{{}}
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
assert.Equal(t, status.Error(codes.PermissionDenied, "permission denied: clusters, update, https://server1"), err)
|
||||
})
|
||||
|
|
@ -190,7 +190,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.NamespaceResourceBlacklist = []metav1.GroupKind{{}}
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
assert.Equal(t, status.Error(codes.PermissionDenied, "permission denied: clusters, update, https://server1"), err)
|
||||
})
|
||||
|
|
@ -209,7 +209,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.Destinations = updatedProj.Spec.Destinations[1:]
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
|
@ -226,7 +226,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.Destinations = updatedProj.Spec.Destinations[1:]
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.Error(t, err)
|
||||
statusCode, _ := status.FromError(err)
|
||||
|
|
@ -246,7 +246,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.SourceRepos = []string{}
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
|
@ -263,7 +263,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := existingProj.DeepCopy()
|
||||
updatedProj.Spec.SourceRepos = []string{}
|
||||
|
||||
_, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
_, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.Error(t, err)
|
||||
statusCode, _ := status.FromError(err)
|
||||
|
|
@ -284,7 +284,7 @@ func TestProjectServer(t *testing.T) {
|
|||
updatedProj := proj.DeepCopy()
|
||||
updatedProj.Spec.SourceRepos = []string{"https://github.com/argoproj/*"}
|
||||
|
||||
res, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
res, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, res.Spec.SourceRepos, updatedProj.Spec.SourceRepos)
|
||||
|
|
@ -313,7 +313,7 @@ func TestProjectServer(t *testing.T) {
|
|||
{Namespace: "org1-*", Server: "https://server1"},
|
||||
}
|
||||
|
||||
res, err := projectServer.Update(context.Background(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
res, err := projectServer.Update(t.Context(), &project.ProjectUpdateRequest{Project: updatedProj})
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, res.Spec.Destinations, updatedProj.Spec.Destinations)
|
||||
|
|
@ -323,7 +323,7 @@ func TestProjectServer(t *testing.T) {
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(&existingProj), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
|
||||
_, err := projectServer.Delete(context.Background(), &project.ProjectQuery{Name: "test"})
|
||||
_, err := projectServer.Delete(t.Context(), &project.ProjectQuery{Name: "test"})
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
|
@ -336,7 +336,7 @@ func TestProjectServer(t *testing.T) {
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(&defaultProj), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
|
||||
_, err := projectServer.Delete(context.Background(), &project.ProjectQuery{Name: defaultProj.Name})
|
||||
_, err := projectServer.Delete(t.Context(), &project.ProjectQuery{Name: defaultProj.Name})
|
||||
statusCode, _ := status.FromError(err)
|
||||
assert.Equal(t, codes.InvalidArgument, statusCode.Code())
|
||||
})
|
||||
|
|
@ -350,7 +350,7 @@ func TestProjectServer(t *testing.T) {
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(&existingProj, &existingApp), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
|
||||
_, err := projectServer.Delete(context.Background(), &project.ProjectQuery{Name: "test"})
|
||||
_, err := projectServer.Delete(t.Context(), &project.ProjectQuery{Name: "test"})
|
||||
|
||||
require.Error(t, err)
|
||||
statusCode, _ := status.FromError(err)
|
||||
|
|
@ -363,7 +363,7 @@ func TestProjectServer(t *testing.T) {
|
|||
_ = enforcer.SetBuiltinPolicy(`p, *, *, *, *, deny`)
|
||||
enforcer.SetClaimsEnforcerFunc(nil)
|
||||
//nolint:staticcheck
|
||||
ctx = context.WithValue(context.Background(), "claims", &jwt.MapClaims{"groups": []string{"my-group"}})
|
||||
ctx = context.WithValue(t.Context(), "claims", &jwt.MapClaims{"groups": []string{"my-group"}})
|
||||
policyEnf := rbacpolicy.NewRBACPolicyEnforcer(enforcer, nil)
|
||||
policyEnf.SetScopes([]string{"groups"})
|
||||
|
||||
|
|
@ -401,7 +401,7 @@ func TestProjectServer(t *testing.T) {
|
|||
sessionMgr := session.NewSessionManager(settingsMgr, test.NewFakeProjListerFromInterface(clientset.ArgoprojV1alpha1().AppProjects("default")), "", nil, session.NewUserStateStorage(nil))
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), clientset, enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
tokenResponse, err := projectServer.CreateToken(context.Background(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 100})
|
||||
tokenResponse, err := projectServer.CreateToken(t.Context(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 100})
|
||||
require.NoError(t, err)
|
||||
claims, _, err := sessionMgr.Parse(tokenResponse.Token)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -422,7 +422,7 @@ func TestProjectServer(t *testing.T) {
|
|||
sessionMgr := session.NewSessionManager(settingsMgr, test.NewFakeProjListerFromInterface(clientset.ArgoprojV1alpha1().AppProjects("default")), "", nil, session.NewUserStateStorage(nil))
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), clientset, enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
tokenResponse, err := projectServer.CreateToken(context.Background(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
tokenResponse, err := projectServer.CreateToken(t.Context(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
require.NoError(t, err)
|
||||
claims, _, err := sessionMgr.Parse(tokenResponse.Token)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -443,7 +443,7 @@ func TestProjectServer(t *testing.T) {
|
|||
sessionMgr := session.NewSessionManager(settingsMgr, test.NewFakeProjListerFromInterface(clientset.ArgoprojV1alpha1().AppProjects("default")), "", nil, session.NewUserStateStorage(nil))
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), clientset, enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
tokenResponse, err := projectServer.CreateToken(context.Background(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
tokenResponse, err := projectServer.CreateToken(t.Context(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
|
||||
require.NoError(t, err)
|
||||
claims, _, err := sessionMgr.Parse(tokenResponse.Token)
|
||||
|
|
@ -456,7 +456,7 @@ func TestProjectServer(t *testing.T) {
|
|||
assert.Equal(t, expectedSubject, subject)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err1 := projectServer.CreateToken(context.Background(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
_, err1 := projectServer.CreateToken(t.Context(), &project.ProjectTokenCreateRequest{Project: projectWithRole.Name, Role: tokenName, ExpiresIn: 1, Id: id})
|
||||
expectedErr := fmt.Sprintf("rpc error: code = InvalidArgument desc = rpc error: code = InvalidArgument desc = Token id '%s' has been used. ", id)
|
||||
assert.EqualError(t, err1, expectedErr)
|
||||
})
|
||||
|
|
@ -503,7 +503,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithToken), enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
_, err := projectServer.DeleteToken(ctx, &project.ProjectTokenDeleteRequest{Project: projWithToken.Name, Role: tokenName, Iat: issuedAt})
|
||||
require.NoError(t, err)
|
||||
projWithoutToken, err := projectServer.Get(context.Background(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
projWithoutToken, err := projectServer.Get(t.Context(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, projWithoutToken.Spec.Roles, 1)
|
||||
assert.Len(t, projWithoutToken.Spec.Roles[0].JWTTokens, 1)
|
||||
|
|
@ -527,7 +527,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithToken), enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
_, err := projectServer.DeleteToken(ctx, &project.ProjectTokenDeleteRequest{Project: projWithToken.Name, Role: tokenName, Iat: secondIssuedAt, Id: id})
|
||||
require.NoError(t, err)
|
||||
projWithoutToken, err := projectServer.Get(context.Background(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
projWithoutToken, err := projectServer.Get(t.Context(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, projWithoutToken.Spec.Roles, 1)
|
||||
assert.Len(t, projWithoutToken.Spec.Roles[0].JWTTokens, 1)
|
||||
|
|
@ -544,9 +544,9 @@ p, role:admin, projects, update, *, allow`)
|
|||
projWithToken.Spec.Roles = append(projWithToken.Spec.Roles, token)
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithToken), enforcer, sync.NewKeyLock(), sessionMgr, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
_, err := projectServer.CreateToken(context.Background(), &project.ProjectTokenCreateRequest{Project: projWithToken.Name, Role: tokenName})
|
||||
_, err := projectServer.CreateToken(t.Context(), &project.ProjectTokenCreateRequest{Project: projWithToken.Name, Role: tokenName})
|
||||
require.NoError(t, err)
|
||||
projWithTwoTokens, err := projectServer.Get(context.Background(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
projWithTwoTokens, err := projectServer.Get(t.Context(), &project.ProjectQuery{Name: projWithToken.Name})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, projWithTwoTokens.Spec.Roles, 1)
|
||||
assert.Len(t, projWithTwoTokens.Spec.Roles[0].JWTTokens, 2)
|
||||
|
|
@ -559,7 +559,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(proj), enforcer, sync.NewKeyLock(), nil, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: proj}
|
||||
updatedProj, err := projectServer.Update(context.Background(), request)
|
||||
updatedProj, err := projectServer.Update(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, wildSourceRepo, updatedProj.Spec.SourceRepos[1])
|
||||
})
|
||||
|
|
@ -578,7 +578,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, policyEnf, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
t.Log(projWithRole.Spec.Roles[0].Policies[0])
|
||||
expectedPolicy := fmt.Sprintf(policyTemplate, projWithRole.Name, role.Name, action, projWithRole.Name, object, effect)
|
||||
|
|
@ -600,7 +600,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
expectedErr := fmt.Sprintf("rpc error: code = AlreadyExists desc = policy '%s' already exists for role '%s'", policy, roleName)
|
||||
assert.EqualError(t, err, expectedErr)
|
||||
})
|
||||
|
|
@ -620,7 +620,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
assert.ErrorContains(t, err, "object must be of form 'test/*', 'test[/<NAMESPACE>]/<APPNAME>' or 'test/<APPNAME>'")
|
||||
})
|
||||
|
||||
|
|
@ -639,7 +639,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
assert.ErrorContains(t, err, "policy subject must be: 'proj:test:testRole'")
|
||||
})
|
||||
|
||||
|
|
@ -658,7 +658,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
assert.ErrorContains(t, err, "policy subject must be: 'proj:test:testRole'")
|
||||
})
|
||||
|
||||
|
|
@ -676,7 +676,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
_, err := projectServer.Update(context.Background(), request)
|
||||
_, err := projectServer.Update(t.Context(), request)
|
||||
assert.ErrorContains(t, err, "effect must be: 'allow' or 'deny'")
|
||||
})
|
||||
|
||||
|
|
@ -695,7 +695,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
projectServer := NewServer("default", fake.NewSimpleClientset(), apps.NewSimpleClientset(projWithRole), enforcer, sync.NewKeyLock(), nil, nil, projInformer, settingsMgr, argoDB, testEnableEventList)
|
||||
request := &project.ProjectUpdateRequest{Project: projWithRole}
|
||||
updateProj, err := projectServer.Update(context.Background(), request)
|
||||
updateProj, err := projectServer.Update(t.Context(), request)
|
||||
require.NoError(t, err)
|
||||
expectedPolicy := fmt.Sprintf(policyTemplate, projWithRole.Name, roleName, action, projWithRole.Name, object, effect)
|
||||
assert.Equal(t, expectedPolicy, updateProj.Spec.Roles[0].Policies[0])
|
||||
|
|
@ -732,7 +732,7 @@ p, role:admin, projects, update, *, allow`)
|
|||
_ = enforcer.SetBuiltinPolicy(`p, *, *, *, *, deny`)
|
||||
enforcer.SetClaimsEnforcerFunc(nil)
|
||||
//nolint:staticcheck
|
||||
ctx := context.WithValue(context.Background(), "claims", &jwt.MapClaims{"groups": []string{"my-group"}})
|
||||
ctx := context.WithValue(t.Context(), "claims", &jwt.MapClaims{"groups": []string{"my-group"}})
|
||||
|
||||
sessionMgr := session.NewSessionManager(settingsMgr, test.NewFakeProjLister(), "", nil, session.NewUserStateStorage(nil))
|
||||
projectWithSyncWindows := existingProj.DeepCopy()
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ func Test_createRBACObject(t *testing.T) {
|
|||
|
||||
func TestRepositoryServer(t *testing.T) {
|
||||
kubeclientset := fake.NewSimpleClientset(&argocdCM, &argocdSecret)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, testNamespace)
|
||||
enforcer := newEnforcer(kubeclientset)
|
||||
appLister, projInformer := newAppAndProjLister(defaultProj)
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
|
||||
|
|
@ -267,7 +267,7 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
s := NewServer(&repoServerClientset, argoDB, enforcer, nil, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
url := "https://test"
|
||||
repo, _ := s.getRepo(context.TODO(), url, "")
|
||||
repo, _ := s.getRepo(t.Context(), url, "")
|
||||
assert.Equal(t, repo.Repo, url)
|
||||
})
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
s := NewServer(&repoServerClientset, argoDB, enforcer, nil, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
url := "https://test"
|
||||
_, err := s.ValidateAccess(context.TODO(), &repository.RepoAccessQuery{
|
||||
_, err := s.ValidateAccess(t.Context(), &repository.RepoAccessQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -291,12 +291,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -316,12 +316,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
Username: "foo",
|
||||
InheritedCreds: true,
|
||||
}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{testRepo}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(testRepo, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{testRepo}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(testRepo, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -337,12 +337,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return(nil, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(nil, errors.New("some error"))
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(nil, errors.New("some error"))
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
assert.Nil(t, repo)
|
||||
|
|
@ -356,12 +356,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(false, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(false, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
assert.Nil(t, repo)
|
||||
|
|
@ -375,12 +375,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: url, Username: "test", Password: "it's a secret", GitHubAppEnterpriseBaseURL: "https://ghe.example.com/api/v3", GithubAppId: 123456, GithubAppInstallationId: 789}}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(&appsv1.Repository{Repo: url, Username: "test", Password: "it's a secret"}, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: url, Username: "test", Password: "it's a secret", GitHubAppEnterpriseBaseURL: "https://ghe.example.com/api/v3", GithubAppId: 123456, GithubAppInstallationId: 789}}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(&appsv1.Repository{Repo: url, Username: "test", Password: "it's a secret"}, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -398,12 +398,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(&appsv1.Repository{Repo: url, Username: "test"}, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(&appsv1.Repository{Repo: url, Username: "test"}, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -420,12 +420,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", context.TODO(), url, "").Return(true, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: url}}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("RepositoryExists", t.Context(), url, "").Return(true, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.Get(context.TODO(), &repository.RepoQuery{
|
||||
repo, err := s.Get(t.Context(), &repository.RepoQuery{
|
||||
Repo: url,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -439,14 +439,14 @@ func TestRepositoryServer(t *testing.T) {
|
|||
repoServerClientset := mocks.Clientset{RepoServerServiceClient: &repoServerClient}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), "test").Return(nil, errors.New("not found"))
|
||||
db.On("CreateRepository", context.TODO(), mock.Anything).Return(&apiclient.TestRepositoryResponse{}).Return(&appsv1.Repository{
|
||||
db.On("GetRepository", t.Context(), "test").Return(nil, errors.New("not found"))
|
||||
db.On("CreateRepository", t.Context(), mock.Anything).Return(&apiclient.TestRepositoryResponse{}).Return(&appsv1.Repository{
|
||||
Repo: "repo",
|
||||
Project: "proj",
|
||||
}, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.CreateRepository(context.TODO(), &repository.RepoCreateRequest{
|
||||
repo, err := s.CreateRepository(t.Context(), &repository.RepoCreateRequest{
|
||||
Repo: &appsv1.Repository{
|
||||
Repo: "test",
|
||||
Username: "test",
|
||||
|
|
@ -467,15 +467,15 @@ func TestRepositoryServer(t *testing.T) {
|
|||
}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), "test", "").Return(&appsv1.Repository{
|
||||
db.On("GetRepository", t.Context(), "test", "").Return(&appsv1.Repository{
|
||||
Repo: "test",
|
||||
Username: "test",
|
||||
}, nil)
|
||||
db.On("CreateRepository", context.TODO(), mock.Anything).Return(nil, status.Errorf(codes.AlreadyExists, "repository already exists"))
|
||||
db.On("UpdateRepository", context.TODO(), mock.Anything).Return(r, nil)
|
||||
db.On("CreateRepository", t.Context(), mock.Anything).Return(nil, status.Errorf(codes.AlreadyExists, "repository already exists"))
|
||||
db.On("UpdateRepository", t.Context(), mock.Anything).Return(r, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
repo, err := s.CreateRepository(context.TODO(), &repository.RepoCreateRequest{
|
||||
repo, err := s.CreateRepository(t.Context(), &repository.RepoCreateRequest{
|
||||
Repo: r,
|
||||
Upsert: true,
|
||||
})
|
||||
|
|
@ -493,12 +493,12 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "argocd").Return(nil, nil)
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(nil, nil)
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{&fakeRepo, &fakeRepo}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "argocd").Return(nil, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(nil, nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{&fakeRepo, &fakeRepo}, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projInformer, testNamespace, settingsMgr, false)
|
||||
resp, err := s.ListRepositories(context.TODO(), &repository.RepoQuery{})
|
||||
resp, err := s.ListRepositories(t.Context(), &repository.RepoQuery{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, resp.Items, 2)
|
||||
})
|
||||
|
|
@ -506,7 +506,7 @@ func TestRepositoryServer(t *testing.T) {
|
|||
|
||||
func TestRepositoryServerListApps(t *testing.T) {
|
||||
kubeclientset := fake.NewSimpleClientset(&argocdCM, &argocdSecret)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, testNamespace)
|
||||
|
||||
t.Run("Test_WithoutAppCreateUpdatePrivileges", func(t *testing.T) {
|
||||
repoServerClient := mocks.RepoServerServiceClient{}
|
||||
|
|
@ -516,11 +516,11 @@ func TestRepositoryServerListApps(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.ListApps(context.TODO(), &repository.RepoAppsQuery{
|
||||
resp, err := s.ListApps(t.Context(), &repository.RepoAppsQuery{
|
||||
Repo: "https://test",
|
||||
Revision: "HEAD",
|
||||
AppName: "foo",
|
||||
|
|
@ -539,17 +539,17 @@ func TestRepositoryServerListApps(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
repoServerClient.On("ListApps", context.TODO(), mock.Anything).Return(&apiclient.AppList{
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
repoServerClient.On("ListApps", t.Context(), mock.Anything).Return(&apiclient.AppList{
|
||||
Apps: map[string]string{
|
||||
"path/to/dir": "Kustomize",
|
||||
},
|
||||
}, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.ListApps(context.TODO(), &repository.RepoAppsQuery{
|
||||
resp, err := s.ListApps(t.Context(), &repository.RepoAppsQuery{
|
||||
Repo: "https://test",
|
||||
Revision: "HEAD",
|
||||
AppName: "foo",
|
||||
|
|
@ -570,17 +570,17 @@ func TestRepositoryServerListApps(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
repoServerClient.On("ListApps", context.TODO(), mock.Anything).Return(&apiclient.AppList{
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
repoServerClient.On("ListApps", t.Context(), mock.Anything).Return(&apiclient.AppList{
|
||||
Apps: map[string]string{
|
||||
"path/to/dir": "Kustomize",
|
||||
},
|
||||
}, nil)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.ListApps(context.TODO(), &repository.RepoAppsQuery{
|
||||
resp, err := s.ListApps(t.Context(), &repository.RepoAppsQuery{
|
||||
Repo: "https://test",
|
||||
Revision: "HEAD",
|
||||
AppName: "foo",
|
||||
|
|
@ -593,7 +593,7 @@ func TestRepositoryServerListApps(t *testing.T) {
|
|||
|
||||
func TestRepositoryServerGetAppDetails(t *testing.T) {
|
||||
kubeclientset := fake.NewSimpleClientset(&argocdCM, &argocdSecret)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, testNamespace)
|
||||
|
||||
t.Run("Test_WithoutRepoReadPrivileges", func(t *testing.T) {
|
||||
repoServerClient := mocks.RepoServerServiceClient{}
|
||||
|
|
@ -603,11 +603,11 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &appsv1.ApplicationSource{
|
||||
RepoURL: url,
|
||||
},
|
||||
|
|
@ -626,11 +626,11 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &appsv1.ApplicationSource{
|
||||
RepoURL: url,
|
||||
},
|
||||
|
|
@ -648,11 +648,11 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &appsv1.ApplicationSource{
|
||||
RepoURL: url,
|
||||
},
|
||||
|
|
@ -669,16 +669,16 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Directory"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &appsv1.ApplicationSource{
|
||||
RepoURL: url,
|
||||
},
|
||||
|
|
@ -695,15 +695,15 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Directory"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProjNoSources)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &appsv1.ApplicationSource{
|
||||
RepoURL: url,
|
||||
},
|
||||
|
|
@ -720,16 +720,16 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Directory"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, guestbookApp)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: guestbookApp.Spec.GetSourcePtrByIndex(0),
|
||||
AppName: "guestbook",
|
||||
AppProject: "default",
|
||||
|
|
@ -745,18 +745,18 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
url := "https://helm.elastic.co"
|
||||
helmRepos := []*appsv1.Repository{{Repo: url}, {Repo: url}}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Helm"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, multiSourceApp001)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
sources := multiSourceApp001.Spec.GetSources()
|
||||
assert.Len(t, sources, 2)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &sources[0],
|
||||
AppName: multiSourceApp001AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -765,7 +765,7 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
assert.Equal(t, expectedResp, *resp)
|
||||
assert.Equal(t, "Helm", resp.Type)
|
||||
// Next source
|
||||
resp, err = s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err = s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &sources[1],
|
||||
AppName: multiSourceApp001AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -783,22 +783,22 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
url1 := "https://helm.elastic.co"
|
||||
helmRepos := []*appsv1.Repository{{Repo: url0}, {Repo: url1}}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", context.TODO(), url0, "default").Return(&appsv1.Repository{Repo: url0}, nil)
|
||||
db.On("GetRepository", context.TODO(), url1, "default").Return(&appsv1.Repository{Repo: url1}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", t.Context(), url0, "default").Return(&appsv1.Repository{Repo: url0}, nil)
|
||||
db.On("GetRepository", t.Context(), url1, "default").Return(&appsv1.Repository{Repo: url1}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp0 := apiclient.RepoAppDetailsResponse{Type: "Plugin"}
|
||||
expectedResp1 := apiclient.RepoAppDetailsResponse{Type: "Helm"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.MatchedBy(func(req *apiclient.RepoServerAppDetailsQuery) bool { return req.Source.RepoURL == url0 })).Return(&expectedResp0, nil)
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.MatchedBy(func(req *apiclient.RepoServerAppDetailsQuery) bool { return req.Source.RepoURL == url1 })).Return(&expectedResp1, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.MatchedBy(func(req *apiclient.RepoServerAppDetailsQuery) bool { return req.Source.RepoURL == url0 })).Return(&expectedResp0, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.MatchedBy(func(req *apiclient.RepoServerAppDetailsQuery) bool { return req.Source.RepoURL == url1 })).Return(&expectedResp1, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, multiSourceApp002)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
sources := multiSourceApp002.Spec.GetSources()
|
||||
assert.Len(t, sources, 2)
|
||||
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &sources[0],
|
||||
AppName: multiSourceApp002AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -807,7 +807,7 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
assert.Equal(t, "Plugin", resp.Type)
|
||||
assert.Equal(t, expectedResp0, *resp)
|
||||
// Next source
|
||||
resp, err = s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err = s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: &sources[1],
|
||||
AppName: multiSourceApp002AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -823,11 +823,11 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "mismatch").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "mismatch").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, guestbookApp)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: guestbookApp.Spec.GetSourcePtrByIndex(0),
|
||||
AppName: "guestbook",
|
||||
AppProject: "mismatch",
|
||||
|
|
@ -842,13 +842,13 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, guestbookApp)
|
||||
differentSource := guestbookApp.Spec.Source.DeepCopy()
|
||||
differentSource.Helm.ValueFiles = []string{"/etc/passwd"}
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: differentSource,
|
||||
AppName: "guestbook",
|
||||
AppProject: "default",
|
||||
|
|
@ -863,18 +863,18 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://test"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Directory"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, guestbookApp)
|
||||
previousSource := guestbookApp.Status.History[0].Source.DeepCopy()
|
||||
previousSource.TargetRevision = guestbookApp.Status.History[0].Revision
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: previousSource,
|
||||
AppName: "guestbook",
|
||||
AppProject: "default",
|
||||
|
|
@ -891,19 +891,19 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
url := "https://helm.elastic.co"
|
||||
helmRepos := []*appsv1.Repository{{Repo: url}, {Repo: url}}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(helmRepos, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Helm"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, multiSourceApp001)
|
||||
|
||||
differentSource := multiSourceApp001.Spec.Sources[0].DeepCopy()
|
||||
differentSource.Helm.ValueFiles = []string{"/etc/passwd"}
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: differentSource,
|
||||
AppName: multiSourceApp001AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -920,18 +920,18 @@ func TestRepositoryServerGetAppDetails(t *testing.T) {
|
|||
|
||||
url := "https://helm.elastic.co"
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetRepository", context.TODO(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", context.TODO(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), url, "default").Return(&appsv1.Repository{Repo: url}, nil)
|
||||
db.On("ListHelmRepositories", t.Context(), mock.Anything).Return(nil, nil)
|
||||
db.On("GetProjectRepositories", "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", context.TODO(), "default").Return(nil, nil)
|
||||
db.On("GetProjectClusters", t.Context(), "default").Return(nil, nil)
|
||||
expectedResp := apiclient.RepoAppDetailsResponse{Type: "Directory"}
|
||||
repoServerClient.On("GetAppDetails", context.TODO(), mock.Anything).Return(&expectedResp, nil)
|
||||
repoServerClient.On("GetAppDetails", t.Context(), mock.Anything).Return(&expectedResp, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj, multiSourceApp001)
|
||||
previousSource := multiSourceApp001.Status.History[0].Sources[0].DeepCopy()
|
||||
previousSource.TargetRevision = multiSourceApp001.Status.History[0].Revisions[0]
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.GetAppDetails(context.TODO(), &repository.RepoAppDetailsQuery{
|
||||
resp, err := s.GetAppDetails(t.Context(), &repository.RepoAppDetailsQuery{
|
||||
Source: previousSource,
|
||||
AppName: multiSourceApp001AppName,
|
||||
AppProject: "default",
|
||||
|
|
@ -984,7 +984,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "empty project and no repos",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1000,7 +1000,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "empty project and no matching repos",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{}, nil
|
||||
},
|
||||
|
|
@ -1014,7 +1014,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "empty project + matching repo with an empty project",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1036,7 +1036,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "empty project + matching repo with a non-empty project",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1058,7 +1058,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "non-empty project + matching repo with an empty project",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1077,7 +1077,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "non-empty project + matching repo with a matching project",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1099,7 +1099,7 @@ func TestGetRepository(t *testing.T) {
|
|||
{
|
||||
name: "non-empty project + matching repo with a non-matching project",
|
||||
args: args{
|
||||
ctx: context.TODO(),
|
||||
ctx: t.Context(),
|
||||
listRepositories: func(_ context.Context, _ *repository.RepoQuery) (*appsv1.RepositoryList, error) {
|
||||
return &appsv1.RepositoryList{
|
||||
Items: []*appsv1.Repository{
|
||||
|
|
@ -1133,7 +1133,7 @@ func TestDeleteRepository(t *testing.T) {
|
|||
}
|
||||
|
||||
kubeclientset := fake.NewSimpleClientset(&argocdCM, &argocdSecret)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeclientset, testNamespace)
|
||||
|
||||
for name, repo := range repositories {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
|
@ -1144,13 +1144,13 @@ func TestDeleteRepository(t *testing.T) {
|
|||
enforcer := newEnforcer(kubeclientset)
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("DeleteRepository", context.TODO(), repo, "default").Return(nil)
|
||||
db.On("ListRepositories", context.TODO()).Return([]*appsv1.Repository{{Repo: repo, Project: "default"}}, nil)
|
||||
db.On("GetRepository", context.TODO(), repo, "default").Return(&appsv1.Repository{Repo: repo, Project: "default"}, nil)
|
||||
db.On("DeleteRepository", t.Context(), repo, "default").Return(nil)
|
||||
db.On("ListRepositories", t.Context()).Return([]*appsv1.Repository{{Repo: repo, Project: "default"}}, nil)
|
||||
db.On("GetRepository", t.Context(), repo, "default").Return(&appsv1.Repository{Repo: repo, Project: "default"}, nil)
|
||||
appLister, projLister := newAppAndProjLister(defaultProj)
|
||||
|
||||
s := NewServer(&repoServerClientset, db, enforcer, newFixtures().Cache, appLister, projLister, testNamespace, settingsMgr, false)
|
||||
resp, err := s.DeleteRepository(context.TODO(), &repository.RepoQuery{Repo: repo, AppProject: "default"})
|
||||
resp, err := s.DeleteRepository(t.Context(), &repository.RepoQuery{Repo: repo, AppProject: "default"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, repository.RepoResponse{}, *resp)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func TestUserAgent(t *testing.T) {
|
|||
|
||||
cancelInformer := test.StartInformer(s.projInformer)
|
||||
defer cancelInformer()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
s.Init(ctx)
|
||||
go s.Run(ctx, lns)
|
||||
|
|
@ -99,7 +99,7 @@ func Test_StaticHeaders(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
cancelInformer := test.StartInformer(s.projInformer)
|
||||
defer cancelInformer()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
s.Init(ctx)
|
||||
go s.Run(ctx, lns)
|
||||
|
|
@ -128,7 +128,7 @@ func Test_StaticHeaders(t *testing.T) {
|
|||
defer cancelInformer()
|
||||
lns, err := s.Listen()
|
||||
require.NoError(t, err)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
s.Init(ctx)
|
||||
go s.Run(ctx, lns)
|
||||
|
|
@ -157,7 +157,7 @@ func Test_StaticHeaders(t *testing.T) {
|
|||
defer cancelInformer()
|
||||
lns, err := s.Listen()
|
||||
require.NoError(t, err)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
s.Init(ctx)
|
||||
go s.Run(ctx, lns)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ func fakeServer(t *testing.T) (*FakeArgoCDServer, func()) {
|
|||
DynamicClientset: dynamicClient,
|
||||
KubeControllerClientset: fakeClient,
|
||||
}
|
||||
srv := NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
srv := NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
fakeSrv := &FakeArgoCDServer{srv, tmpAssetsDir}
|
||||
return fakeSrv, closer
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
mockRepoClient := &mocks.Clientset{RepoServerServiceClient: &mocks.RepoServerServiceClient{}}
|
||||
|
||||
t.Run("TestEnforceProjectTokenSuccessful", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
cancel := test.StartInformer(s.projInformer)
|
||||
defer cancel()
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "iat": defaultIssuedAt}
|
||||
|
|
@ -137,21 +137,21 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TestEnforceProjectTokenWithDiffCreateAtFailure", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
diffCreateAt := defaultIssuedAt + 1
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "iat": diffCreateAt}
|
||||
assert.False(t, s.enf.Enforce(claims, "applications", "get", defaultTestObject))
|
||||
})
|
||||
|
||||
t.Run("TestEnforceProjectTokenIncorrectSubFormatFailure", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
invalidSub := "proj:test"
|
||||
claims := jwt.MapClaims{"sub": invalidSub, "iat": defaultIssuedAt}
|
||||
assert.False(t, s.enf.Enforce(claims, "applications", "get", defaultTestObject))
|
||||
})
|
||||
|
||||
t.Run("TestEnforceProjectTokenNoTokenFailure", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
nonExistentToken := "fake-token"
|
||||
invalidSub := fmt.Sprintf(subFormat, projectName, nonExistentToken)
|
||||
claims := jwt.MapClaims{"sub": invalidSub, "iat": defaultIssuedAt}
|
||||
|
|
@ -161,7 +161,7 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
t.Run("TestEnforceProjectTokenNotJWTTokenFailure", func(t *testing.T) {
|
||||
proj := existingProj.DeepCopy()
|
||||
proj.Spec.Roles[0].JWTTokens = nil
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(proj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(proj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "iat": defaultIssuedAt}
|
||||
assert.False(t, s.enf.Enforce(claims, "applications", "get", defaultTestObject))
|
||||
})
|
||||
|
|
@ -174,7 +174,7 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
proj := existingProj.DeepCopy()
|
||||
proj.Spec.Roles[0] = role
|
||||
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(proj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(proj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
cancel := test.StartInformer(s.projInformer)
|
||||
defer cancel()
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "iat": defaultIssuedAt}
|
||||
|
|
@ -185,7 +185,7 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TestEnforceProjectTokenWithIdSuccessful", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
cancel := test.StartInformer(s.projInformer)
|
||||
defer cancel()
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "jti": defaultId}
|
||||
|
|
@ -194,7 +194,7 @@ func TestEnforceProjectToken(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TestEnforceProjectTokenWithInvalidIdFailure", func(t *testing.T) {
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
invalidId := "invalidId"
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "jti": defaultId}
|
||||
res := s.enf.Enforce(claims, "applications", "get", invalidId)
|
||||
|
|
@ -278,10 +278,10 @@ func TestInitializingExistingDefaultProject(t *testing.T) {
|
|||
RepoClientset: mockRepoClient,
|
||||
}
|
||||
|
||||
argocd := NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
argocd := NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
assert.NotNil(t, argocd)
|
||||
|
||||
proj, err := appClientSet.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Get(context.Background(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
proj, err := appClientSet.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Get(t.Context(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, proj)
|
||||
assert.Equal(t, v1alpha1.DefaultAppProjectName, proj.Name)
|
||||
|
|
@ -301,10 +301,10 @@ func TestInitializingNotExistingDefaultProject(t *testing.T) {
|
|||
RepoClientset: mockRepoClient,
|
||||
}
|
||||
|
||||
argocd := NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
argocd := NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
assert.NotNil(t, argocd)
|
||||
|
||||
proj, err := appClientSet.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Get(context.Background(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
proj, err := appClientSet.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Get(t.Context(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, proj)
|
||||
assert.Equal(t, v1alpha1.DefaultAppProjectName, proj.Name)
|
||||
|
|
@ -343,7 +343,7 @@ func TestEnforceProjectGroups(t *testing.T) {
|
|||
}
|
||||
mockRepoClient := &mocks.Clientset{RepoServerServiceClient: &mocks.RepoServerServiceClient{}}
|
||||
kubeclientset := fake.NewClientset(test.NewFakeConfigMap(), test.NewFakeSecret())
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
cancel := test.StartInformer(s.projInformer)
|
||||
defer cancel()
|
||||
claims := jwt.MapClaims{
|
||||
|
|
@ -358,7 +358,7 @@ func TestEnforceProjectGroups(t *testing.T) {
|
|||
log.Println(existingProj.ProjectPoliciesString())
|
||||
existingProj.Spec.Roles[0].Groups = nil
|
||||
log.Println(existingProj.ProjectPoliciesString())
|
||||
_, _ = s.AppClientset.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Update(context.Background(), &existingProj, metav1.UpdateOptions{})
|
||||
_, _ = s.AppClientset.ArgoprojV1alpha1().AppProjects(test.FakeArgoCDNamespace).Update(t.Context(), &existingProj, metav1.UpdateOptions{})
|
||||
time.Sleep(100 * time.Millisecond) // this lets the informer get synced
|
||||
assert.False(t, s.enf.Enforce(claims, "projects", "get", existingProj.ObjectMeta.Name))
|
||||
assert.False(t, s.enf.Enforce(claims, "applications", "get", defaultTestObject))
|
||||
|
|
@ -405,7 +405,7 @@ func TestRevokedToken(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
s := NewServer(context.Background(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
s := NewServer(t.Context(), ArgoCDServerOpts{Namespace: test.FakeArgoCDNamespace, KubeClientset: kubeclientset, AppClientset: apps.NewSimpleClientset(&existingProj), RepoClientset: mockRepoClient}, ApplicationSetOpts{})
|
||||
cancel := test.StartInformer(s.projInformer)
|
||||
defer cancel()
|
||||
claims := jwt.MapClaims{"sub": defaultSub, "iat": defaultIssuedAt}
|
||||
|
|
@ -428,7 +428,7 @@ func TestGracefulShutdown(t *testing.T) {
|
|||
redis, redisCloser := test.NewInMemoryRedis()
|
||||
defer redisCloser()
|
||||
s := NewServer(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
ArgoCDServerOpts{
|
||||
ListenPort: port,
|
||||
Namespace: test.FakeArgoCDNamespace,
|
||||
|
|
@ -451,7 +451,7 @@ func TestGracefulShutdown(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
shutdown := false
|
||||
runCtx, runCancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
runCtx, runCancel := context.WithTimeout(t.Context(), 2*time.Second)
|
||||
defer runCancel()
|
||||
|
||||
err = s.healthCheck(&http.Request{URL: &url.URL{Path: "/healthz", RawQuery: "full=true"}})
|
||||
|
|
@ -526,12 +526,12 @@ func TestAuthenticate(t *testing.T) {
|
|||
AppClientset: appClientSet,
|
||||
RepoClientset: mockRepoClient,
|
||||
}
|
||||
argocd := NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
ctx := context.Background()
|
||||
argocd := NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
ctx := t.Context()
|
||||
if testData.user != "" {
|
||||
token, err := argocd.sessionMgr.Create(testData.user, 0, "abc")
|
||||
require.NoError(t, err)
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs(apiclient.MetaDataTokenKey, token))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.Pairs(apiclient.MetaDataTokenKey, token))
|
||||
}
|
||||
|
||||
_, err := argocd.Authenticate(ctx)
|
||||
|
|
@ -665,7 +665,7 @@ connectors:
|
|||
if withFakeSSO && useDexForSSO {
|
||||
argoCDOpts.DexServerAddr = ts.URL
|
||||
}
|
||||
argocd = NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
argocd = NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
var err error
|
||||
argocd.ssoClientApp, err = oidc.NewClientApp(argocd.settings, argocd.DexServerAddr, argocd.DexTLSConfig, argocd.BaseHRef, cache.NewInMemoryCache(24*time.Hour))
|
||||
require.NoError(t, err)
|
||||
|
|
@ -733,7 +733,7 @@ func TestGetClaims(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
// Must be declared here to avoid race.
|
||||
ctx := context.Background() //nolint:ineffassign,staticcheck
|
||||
ctx := t.Context() //nolint:ineffassign,staticcheck
|
||||
|
||||
argocd, oidcURL := getTestServer(t, false, true, false, testDataCopy.additionalOIDCConfig)
|
||||
|
||||
|
|
@ -745,7 +745,7 @@ func TestGetClaims(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
tokenString, err := token.SignedString(key)
|
||||
require.NoError(t, err)
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
|
||||
gotClaims, newToken, err := argocd.getClaims(ctx)
|
||||
|
||||
|
|
@ -897,7 +897,7 @@ func TestAuthenticate_3rd_party_JWTs(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
// Must be declared here to avoid race.
|
||||
ctx := context.Background() //nolint:staticcheck
|
||||
ctx := t.Context() //nolint:staticcheck
|
||||
|
||||
argocd, oidcURL := getTestServer(t, testDataCopy.anonymousEnabled, true, testDataCopy.useDex, settings_util.OIDCConfig{})
|
||||
|
||||
|
|
@ -909,7 +909,7 @@ func TestAuthenticate_3rd_party_JWTs(t *testing.T) {
|
|||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, testDataCopy.claims)
|
||||
tokenString, err := token.SignedString([]byte("key"))
|
||||
require.NoError(t, err)
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
|
||||
ctx, err = argocd.Authenticate(ctx)
|
||||
claims := ctx.Value("claims")
|
||||
|
|
@ -956,7 +956,7 @@ func TestAuthenticate_no_request_metadata(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
argocd, _ := getTestServer(t, testDataCopy.anonymousEnabled, true, true, settings_util.OIDCConfig{})
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
ctx, err := argocd.Authenticate(ctx)
|
||||
claims := ctx.Value("claims")
|
||||
|
|
@ -999,13 +999,13 @@ func TestAuthenticate_no_SSO(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
// Must be declared here to avoid race.
|
||||
ctx := context.Background() //nolint:ineffassign,staticcheck
|
||||
ctx := t.Context() //nolint:ineffassign,staticcheck
|
||||
|
||||
argocd, dexURL := getTestServer(t, testDataCopy.anonymousEnabled, false, true, settings_util.OIDCConfig{})
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.RegisteredClaims{Issuer: dexURL + "/api/dex"})
|
||||
tokenString, err := token.SignedString([]byte("key"))
|
||||
require.NoError(t, err)
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.Pairs(apiclient.MetaDataTokenKey, tokenString))
|
||||
|
||||
ctx, err = argocd.Authenticate(ctx)
|
||||
claims := ctx.Value("claims")
|
||||
|
|
@ -1107,10 +1107,10 @@ func TestAuthenticate_bad_request_metadata(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
// Must be declared here to avoid race.
|
||||
ctx := context.Background() //nolint:ineffassign,staticcheck
|
||||
ctx := t.Context() //nolint:ineffassign,staticcheck
|
||||
|
||||
argocd, _ := getTestServer(t, testDataCopy.anonymousEnabled, true, true, settings_util.OIDCConfig{})
|
||||
ctx = metadata.NewIncomingContext(context.Background(), testDataCopy.metadata)
|
||||
ctx = metadata.NewIncomingContext(t.Context(), testDataCopy.metadata)
|
||||
|
||||
ctx, err := argocd.Authenticate(ctx)
|
||||
claims := ctx.Value("claims")
|
||||
|
|
@ -1149,11 +1149,11 @@ func TestTranslateGrpcCookieHeader(t *testing.T) {
|
|||
AppClientset: apps.NewSimpleClientset(),
|
||||
RepoClientset: &mocks.Clientset{RepoServerServiceClient: &mocks.RepoServerServiceClient{}},
|
||||
}
|
||||
argocd := NewServer(context.Background(), argoCDOpts, ApplicationSetOpts{})
|
||||
argocd := NewServer(t.Context(), argoCDOpts, ApplicationSetOpts{})
|
||||
|
||||
t.Run("TokenIsNotEmpty", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
err := argocd.translateGrpcCookieHeader(context.Background(), recorder, &session.SessionResponse{
|
||||
err := argocd.translateGrpcCookieHeader(t.Context(), recorder, &session.SessionResponse{
|
||||
Token: "xyz",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1163,7 +1163,7 @@ func TestTranslateGrpcCookieHeader(t *testing.T) {
|
|||
|
||||
t.Run("TokenIsLongerThan4093", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
err := argocd.translateGrpcCookieHeader(context.Background(), recorder, &session.SessionResponse{
|
||||
err := argocd.translateGrpcCookieHeader(t.Context(), recorder, &session.SessionResponse{
|
||||
Token: "abc.xyz." + strings.Repeat("x", 4093),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1173,7 +1173,7 @@ func TestTranslateGrpcCookieHeader(t *testing.T) {
|
|||
|
||||
t.Run("TokenIsEmpty", func(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
err := argocd.translateGrpcCookieHeader(context.Background(), recorder, &session.SessionResponse{
|
||||
err := argocd.translateGrpcCookieHeader(t.Context(), recorder, &session.SessionResponse{
|
||||
Token: "",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1193,7 +1193,7 @@ func TestInitializeDefaultProject_ProjectDoesNotExist(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
proj, err := argoCDOpts.AppClientset.ArgoprojV1alpha1().
|
||||
AppProjects(test.FakeArgoCDNamespace).Get(context.Background(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
AppProjects(test.FakeArgoCDNamespace).Get(t.Context(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -1227,7 +1227,7 @@ func TestInitializeDefaultProject_ProjectAlreadyInitialized(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
proj, err := argoCDOpts.AppClientset.ArgoprojV1alpha1().
|
||||
AppProjects(test.FakeArgoCDNamespace).Get(context.Background(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
AppProjects(test.FakeArgoCDNamespace).Get(t.Context(), v1alpha1.DefaultAppProjectName, metav1.GetOptions{})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ RUN ln -s /usr/lib/$(uname -m)-linux-gnu /usr/lib/linux-gnu
|
|||
# Please make sure to also check the contained yarn version and update the references below when upgrading this image's version
|
||||
FROM docker.io/library/node:22.9.0@sha256:69e667a79aa41ec0db50bc452a60e705ca16f35285eaf037ebe627a65a5cdf52 AS node
|
||||
|
||||
FROM docker.io/library/golang:1.24.0@sha256:2b1cbf278ce05a2a310a3d695ebb176420117a8cfcfcc4e5e68a1bef5f6354da AS golang
|
||||
FROM docker.io/library/golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418 AS golang
|
||||
|
||||
FROM docker.io/library/registry:2.8@sha256:543dade69668e02e5768d7ea2b0aa4fae6aa7384c9a5a8dbecc2be5136079ddb AS registry
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -110,7 +109,7 @@ test true login, apiKey`, output)
|
|||
closer, client := testAccountClientset.NewSessionClientOrDie()
|
||||
defer io.Close(closer)
|
||||
|
||||
info, err := client.GetUserInfo(context.Background(), &session.GetUserInfoRequest{})
|
||||
info, err := client.GetUserInfo(t.Context(), &session.GetUserInfoRequest{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", info.Username)
|
||||
|
|
@ -129,7 +128,7 @@ func TestLoginBadCredentials(t *testing.T) {
|
|||
}}
|
||||
|
||||
for _, r := range requests {
|
||||
_, err := sessionClient.Create(context.Background(), &r)
|
||||
_, err := sessionClient.Create(t.Context(), &r)
|
||||
require.Error(t, err)
|
||||
errStatus, ok := status.FromError(err)
|
||||
if !assert.True(t, ok) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/gitops-engine/pkg/utils/kube"
|
||||
|
|
@ -71,9 +70,9 @@ func TestBackupExportImport(t *testing.T) {
|
|||
Then().
|
||||
AndCLIOutput(func(_ string, err error) {
|
||||
require.NoError(t, err, "import finished with error")
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(context.Background(), "exported-app1", metav1.GetOptions{})
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), "exported-app1", metav1.GetOptions{})
|
||||
require.NoError(t, err, "failed getting test namespace application after import")
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(context.Background(), "exported-app-other-namespace", metav1.GetOptions{})
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), "exported-app-other-namespace", metav1.GetOptions{})
|
||||
require.NoError(t, err, "failed getting app namespace application after import")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
|
|
@ -38,7 +37,7 @@ func TestNSAutoSyncSelfHealDisabled(t *testing.T) {
|
|||
// app should not be auto-synced if k8s change detected
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Then().
|
||||
|
|
@ -64,7 +63,7 @@ func TestNSAutoSyncSelfHealEnabled(t *testing.T) {
|
|||
When().
|
||||
// app should be auto-synced once k8s change detected
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Refresh(RefreshTypeNormal).
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
|
|
@ -34,7 +33,7 @@ func TestAutoSyncSelfHealDisabled(t *testing.T) {
|
|||
// app should not be auto-synced if k8s change detected
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Refresh(RefreshTypeNormal).
|
||||
|
|
@ -59,7 +58,7 @@ func TestAutoSyncSelfHealEnabled(t *testing.T) {
|
|||
When().
|
||||
// app should be auto-synced once k8s change detected
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Refresh(RefreshTypeNormal).
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ func TestLabelsOnAppK8sEvents(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
events, err := KubeClientset.CoreV1().Events(app.Namespace).List(context.Background(), metav1.ListOptions{
|
||||
events, err := KubeClientset.CoreV1().Events(app.Namespace).List(t.Context(), metav1.ListOptions{
|
||||
FieldSelector: fmt.Sprintf("involvedObject.name=%s,involvedObject.kind=Application", app.Name),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -54,7 +53,7 @@ func TestNoLabelsOnAppK8sEvents(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
events, err := KubeClientset.CoreV1().Events(app.Namespace).List(context.Background(), metav1.ListOptions{
|
||||
events, err := KubeClientset.CoreV1().Events(app.Namespace).List(t.Context(), metav1.ListOptions{
|
||||
FieldSelector: fmt.Sprintf("involvedObject.name=%s,involvedObject.kind=Application", app.Name),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ func TestNamespacedAppCreation(t *testing.T) {
|
|||
When().
|
||||
// ensure that update replaces spec and merge labels and annotations
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
CreateApp("--upsert").
|
||||
|
|
@ -470,7 +470,7 @@ func TestNamespacedAppRollbackSuccessful(t *testing.T) {
|
|||
}}
|
||||
patch, _, err := diff.CreateTwoWayMergePatch(app, appWithHistory, &Application{})
|
||||
require.NoError(t, err)
|
||||
app, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
app, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// sync app and make sure it reaches InSync state
|
||||
|
|
@ -546,7 +546,7 @@ func TestNamespacedManipulateApplicationResources(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
_, err = client.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
_, err = client.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
Name: &app.Name,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
Group: ptr.To(deployment.GroupVersionKind().Group),
|
||||
|
|
@ -576,7 +576,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
res := errors.NewHandler(t).FailOnErr(client.GetResource(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
res := errors.NewHandler(t).FailOnErr(client.GetResource(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Namespace: &app.Spec.Destination.Namespace,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
Kind: ptr.To(kube.SecretKind),
|
||||
|
|
@ -587,7 +587,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
|||
})).(*applicationpkg.ApplicationResourceResponse)
|
||||
assetSecretDataHidden(t, res.GetManifest())
|
||||
|
||||
manifests, err := client.GetManifests(context.Background(), &applicationpkg.ApplicationManifestQuery{
|
||||
manifests, err := client.GetManifests(t.Context(), &applicationpkg.ApplicationManifestQuery{
|
||||
Name: &app.Name,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
})
|
||||
|
|
@ -609,7 +609,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
|||
assert.NotContains(t, err.Error(), "password")
|
||||
|
||||
// patch secret and make sure app is out of sync and diff detects the change
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Secrets(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Secrets(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"test-secret", types.JSONPatchType, []byte(`[
|
||||
{"op": "remove", "path": "/data/username"},
|
||||
{"op": "add", "path": "/stringData", "value": {"password": "foo"}}
|
||||
|
|
@ -633,7 +633,7 @@ func TestNamespacedAppWithSecrets(t *testing.T) {
|
|||
app.Spec.IgnoreDifferences = []ResourceIgnoreDifferences{{
|
||||
Kind: kube.SecretKind, JSONPointers: []string{"/data"},
|
||||
}}
|
||||
errors.NewHandler(t).FailOnErr(client.UpdateSpec(context.Background(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, AppNamespace: ptr.To(fixture.AppNamespace()), Spec: &app.Spec}))
|
||||
errors.NewHandler(t).FailOnErr(client.UpdateSpec(t.Context(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, AppNamespace: ptr.To(fixture.AppNamespace()), Spec: &app.Spec}))
|
||||
}).
|
||||
When().
|
||||
Refresh(RefreshTypeNormal).
|
||||
|
|
@ -673,7 +673,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
|||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
// Patch deployment
|
||||
_, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
_, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "test" }]`), metav1.PatchOptions{})
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
|
|
@ -740,7 +740,7 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
|||
"value": { "syncOptions": ["RespectIgnoreDifferences=true"] }
|
||||
}]`).
|
||||
And(func() {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(3), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
|
|
@ -754,13 +754,13 @@ func TestNamespacedResourceDiffing(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
When().Sync().Then().Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
})
|
||||
|
|
@ -784,7 +784,7 @@ func TestNamespacedKnownTypesInCRDDiffing(t *testing.T) {
|
|||
And(func() {
|
||||
dummyResIf := fixture.DynamicClientset.Resource(dummiesGVR).Namespace(fixture.DeploymentNamespace())
|
||||
patchData := []byte(`{"spec":{"cpu": "2"}}`)
|
||||
errors.NewHandler(t).FailOnErr(dummyResIf.Patch(context.Background(), "dummy-crd-instance", types.MergePatchType, patchData, metav1.PatchOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(dummyResIf.Patch(t.Context(), "dummy-crd-instance", types.MergePatchType, patchData, metav1.PatchOptions{}))
|
||||
}).Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
|
|
@ -863,7 +863,7 @@ func TestNamespacedResourceAction(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &app.Name,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
Group: ptr.To("apps"),
|
||||
|
|
@ -875,7 +875,7 @@ func TestNamespacedResourceAction(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = client.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("apps"),
|
||||
Kind: ptr.To("Deployment"),
|
||||
|
|
@ -887,7 +887,7 @@ func TestNamespacedResourceAction(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", deployment.Labels["sample"])
|
||||
|
|
@ -1036,10 +1036,10 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
|||
closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie()
|
||||
defer io.Close(closer)
|
||||
|
||||
deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
logs, err := cdClient.PodLogs(context.Background(), &applicationpkg.ApplicationPodLogsQuery{
|
||||
logs, err := cdClient.PodLogs(t.Context(), &applicationpkg.ApplicationPodLogsQuery{
|
||||
Group: ptr.To("apps"),
|
||||
Kind: ptr.To("Deployment"),
|
||||
Name: &appName,
|
||||
|
|
@ -1056,7 +1056,7 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
|||
|
||||
expectedError := "Deployment apps guestbook-ui not found as part of application " + appName
|
||||
|
||||
_, err = cdClient.ListResourceEvents(context.Background(), &applicationpkg.ApplicationResourceEventsQuery{
|
||||
_, err = cdClient.ListResourceEvents(t.Context(), &applicationpkg.ApplicationResourceEventsQuery{
|
||||
Name: &appName,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
|
|
@ -1065,7 +1065,7 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, fmt.Sprintf("%s not found as part of application %s", "guestbook-ui", appName))
|
||||
|
||||
_, err = cdClient.GetResource(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
_, err = cdClient.GetResource(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &appName,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
|
|
@ -1076,7 +1076,7 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, expectedError)
|
||||
|
||||
_, err = cdClient.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = cdClient.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &appName,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
|
|
@ -1088,7 +1088,7 @@ func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, expectedError)
|
||||
|
||||
_, err = cdClient.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
_, err = cdClient.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
Name: &appName,
|
||||
AppNamespace: ptr.To(fixture.AppNamespace()),
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
|
|
@ -1155,7 +1155,7 @@ func TestNamespacedPermissions(t *testing.T) {
|
|||
And(func(app *Application) {
|
||||
closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie()
|
||||
defer io.Close(closer)
|
||||
tree, err := cdClient.ResourceTree(context.Background(), &applicationpkg.ResourcesQuery{ApplicationName: &app.Name, AppNamespace: &app.Namespace})
|
||||
tree, err := cdClient.ResourceTree(t.Context(), &applicationpkg.ResourcesQuery{ApplicationName: &app.Name, AppNamespace: &app.Namespace})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, tree.Nodes)
|
||||
assert.Empty(t, tree.OrphanedNodes)
|
||||
|
|
@ -1344,7 +1344,7 @@ func TestNamespacedSelfManagedApps(t *testing.T) {
|
|||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(a *Application) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Second*3)
|
||||
defer cancel()
|
||||
|
||||
reconciledCount := 0
|
||||
|
|
@ -1426,7 +1426,7 @@ func TestNamespacedOrphanedResource(t *testing.T) {
|
|||
Expect(NoConditions()).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "orphaned-configmap",
|
||||
},
|
||||
|
|
@ -1536,7 +1536,7 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
|
|||
}
|
||||
defer func() {
|
||||
log.Infof("Ingress 'sample-ingress' deleted from %s", fixture.TestNamespace())
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(t.Context(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
}()
|
||||
|
||||
svc := &corev1.Service{
|
||||
|
|
@ -1566,8 +1566,8 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
|
|||
},
|
||||
}).
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Create(context.Background(), ingress, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Create(context.Background(), svc, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Create(t.Context(), ingress, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Create(t.Context(), svc, metav1.CreateOptions{}))
|
||||
}).
|
||||
Path(guestbookPath).
|
||||
When().
|
||||
|
|
@ -1592,8 +1592,8 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
|
|||
Expect(DoesNotExist())
|
||||
|
||||
// Make sure prohibited resources are not deleted during application deletion
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Get(t.Context(), "sample-ingress", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{}))
|
||||
}
|
||||
|
||||
func TestNamespacedSyncWithInfos(t *testing.T) {
|
||||
|
|
@ -1634,7 +1634,7 @@ func TestNamespacedCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) {
|
|||
CreateWithNoNameSpace().
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
app, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
app, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, app.Status.Conditions)
|
||||
})
|
||||
|
|
@ -1656,7 +1656,7 @@ func TestNamespacedCreateAppWithNoNameSpaceWhenRequired(t *testing.T) {
|
|||
Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, updatedApp.Status.Conditions, 2)
|
||||
|
|
@ -1682,7 +1682,7 @@ func TestNamespacedCreateAppWithNoNameSpaceWhenRequired2(t *testing.T) {
|
|||
Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, updatedApp.Status.Conditions, 2)
|
||||
|
|
@ -1711,7 +1711,7 @@ func TestNamespacedListResource(t *testing.T) {
|
|||
Expect(NoConditions()).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "orphaned-configmap",
|
||||
},
|
||||
|
|
@ -1854,7 +1854,7 @@ func TestNamespacedNamespaceAutoCreationWithMetadata(t *testing.T) {
|
|||
Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", updatedNamespace, SyncStatusCodeSynced)).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/syncPolicy/managedNamespaceMetadata/labels", "value": {"new":"label"} }]`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Sync().
|
||||
|
|
@ -1873,7 +1873,7 @@ func TestNamespacedNamespaceAutoCreationWithMetadata(t *testing.T) {
|
|||
})).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/syncPolicy/managedNamespaceMetadata/annotations", "value": {"new":"custom-annotation"} }]`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Sync().
|
||||
|
|
@ -2025,7 +2025,7 @@ metadata:
|
|||
})).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.JSONPatchType, []byte(`[{ "op": "add", "path": "/spec/syncPolicy/managedNamespaceMetadata/annotations/something", "value": "hmm" }]`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Sync().
|
||||
|
|
@ -2045,7 +2045,7 @@ metadata:
|
|||
})).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.AppNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.JSONPatchType, []byte(`[{ "op": "remove", "path": "/spec/syncPolicy/managedNamespaceMetadata/annotations/something" }]`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Sync().
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ func TestAppCreation(t *testing.T) {
|
|||
When().
|
||||
// ensure that update replaces spec and merge labels and annotations
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
CreateApp("--upsert").
|
||||
|
|
@ -614,7 +614,7 @@ func TestAppRollbackSuccessful(t *testing.T) {
|
|||
}}
|
||||
patch, _, err := diff.CreateTwoWayMergePatch(app, appWithHistory, &Application{})
|
||||
require.NoError(t, err)
|
||||
app, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(context.Background(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
app, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(t.Context(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// sync app and make sure it reaches InSync state
|
||||
|
|
@ -735,7 +735,7 @@ func TestManipulateApplicationResources(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
_, err = client.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
_, err = client.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To(deployment.GroupVersionKind().Group),
|
||||
Kind: ptr.To(deployment.GroupVersionKind().Kind),
|
||||
|
|
@ -786,7 +786,7 @@ func TestAppWithSecrets(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
res := errors.NewHandler(t).FailOnErr(client.GetResource(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
res := errors.NewHandler(t).FailOnErr(client.GetResource(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Namespace: &app.Spec.Destination.Namespace,
|
||||
Kind: ptr.To(kube.SecretKind),
|
||||
Group: ptr.To(""),
|
||||
|
|
@ -796,7 +796,7 @@ func TestAppWithSecrets(t *testing.T) {
|
|||
})).(*applicationpkg.ApplicationResourceResponse)
|
||||
assetSecretDataHidden(t, res.GetManifest())
|
||||
|
||||
manifests, err := client.GetManifests(context.Background(), &applicationpkg.ApplicationManifestQuery{Name: &app.Name})
|
||||
manifests, err := client.GetManifests(t.Context(), &applicationpkg.ApplicationManifestQuery{Name: &app.Name})
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, manifest := range manifests.Manifests {
|
||||
|
|
@ -815,7 +815,7 @@ func TestAppWithSecrets(t *testing.T) {
|
|||
assert.NotContains(t, err.Error(), "password")
|
||||
|
||||
// patch secret and make sure app is out of sync and diff detects the change
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Secrets(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Secrets(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"test-secret", types.JSONPatchType, []byte(`[
|
||||
{"op": "remove", "path": "/data/username"},
|
||||
{"op": "add", "path": "/stringData", "value": {"password": "foo"}}
|
||||
|
|
@ -839,7 +839,7 @@ func TestAppWithSecrets(t *testing.T) {
|
|||
app.Spec.IgnoreDifferences = []ResourceIgnoreDifferences{{
|
||||
Kind: kube.SecretKind, JSONPointers: []string{"/data"},
|
||||
}}
|
||||
errors.NewHandler(t).FailOnErr(client.UpdateSpec(context.Background(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, Spec: &app.Spec}))
|
||||
errors.NewHandler(t).FailOnErr(client.UpdateSpec(t.Context(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, Spec: &app.Spec}))
|
||||
}).
|
||||
When().
|
||||
Refresh(RefreshTypeNormal).
|
||||
|
|
@ -876,7 +876,7 @@ func TestResourceDiffing(t *testing.T) {
|
|||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
// Patch deployment
|
||||
_, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
_, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "test" }]`), metav1.PatchOptions{})
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
|
|
@ -943,7 +943,7 @@ func TestResourceDiffing(t *testing.T) {
|
|||
"value": { "syncOptions": ["RespectIgnoreDifferences=true"] }
|
||||
}]`).
|
||||
And(func() {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(3), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
|
|
@ -957,13 +957,13 @@ func TestResourceDiffing(t *testing.T) {
|
|||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
}).
|
||||
When().Sync().Then().Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(_ *Application) {
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int32(1), *deployment.Spec.RevisionHistoryLimit)
|
||||
})
|
||||
|
|
@ -984,7 +984,7 @@ func TestKnownTypesInCRDDiffing(t *testing.T) {
|
|||
And(func() {
|
||||
dummyResIf := fixture.DynamicClientset.Resource(dummiesGVR).Namespace(fixture.DeploymentNamespace())
|
||||
patchData := []byte(`{"spec":{"cpu": "2"}}`)
|
||||
errors.NewHandler(t).FailOnErr(dummyResIf.Patch(context.Background(), "dummy-crd-instance", types.MergePatchType, patchData, metav1.PatchOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(dummyResIf.Patch(t.Context(), "dummy-crd-instance", types.MergePatchType, patchData, metav1.PatchOptions{}))
|
||||
}).Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
|
||||
|
|
@ -1054,7 +1054,7 @@ func TestOldStyleResourceAction(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("apps"),
|
||||
Kind: ptr.To("Deployment"),
|
||||
|
|
@ -1065,7 +1065,7 @@ func TestOldStyleResourceAction(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = client.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("apps"),
|
||||
Kind: ptr.To("Deployment"),
|
||||
|
|
@ -1076,7 +1076,7 @@ func TestOldStyleResourceAction(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deployment, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "test", deployment.Labels["sample"])
|
||||
|
|
@ -1160,7 +1160,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("batch"),
|
||||
Kind: ptr.To("CronJob"),
|
||||
|
|
@ -1171,7 +1171,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = client.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("batch"),
|
||||
Kind: ptr.To("CronJob"),
|
||||
|
|
@ -1182,7 +1182,7 @@ func TestNewStyleResourceActionPermitted(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.KubeClientset.BatchV1().Jobs(fixture.DeploymentNamespace()).Get(context.Background(), "hello-123", metav1.GetOptions{})
|
||||
_, err = fixture.KubeClientset.BatchV1().Jobs(fixture.DeploymentNamespace()).Get(t.Context(), "hello-123", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
@ -1271,7 +1271,7 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer io.Close(closer)
|
||||
|
||||
actions, err := client.ListResourceActions(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
actions, err := client.ListResourceActions(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("batch"),
|
||||
Kind: ptr.To("CronJob"),
|
||||
|
|
@ -1282,7 +1282,7 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, []*ResourceAction{{Name: "sample", Disabled: false}}, actions.Actions)
|
||||
|
||||
_, err = client.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = client.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &app.Name,
|
||||
Group: ptr.To("batch"),
|
||||
Kind: ptr.To("CronJob"),
|
||||
|
|
@ -1294,10 +1294,10 @@ func TestNewStyleResourceActionMixedOk(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Assert new Job was created
|
||||
_, err = fixture.KubeClientset.BatchV1().Jobs(fixture.DeploymentNamespace()).Get(context.Background(), "hello-123", metav1.GetOptions{})
|
||||
_, err = fixture.KubeClientset.BatchV1().Jobs(fixture.DeploymentNamespace()).Get(t.Context(), "hello-123", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
// Assert the original CronJob was patched
|
||||
cronJob, err := fixture.KubeClientset.BatchV1().CronJobs(fixture.DeploymentNamespace()).Get(context.Background(), "hello", metav1.GetOptions{})
|
||||
cronJob, err := fixture.KubeClientset.BatchV1().CronJobs(fixture.DeploymentNamespace()).Get(t.Context(), "hello", metav1.GetOptions{})
|
||||
assert.Equal(t, "aValue", cronJob.Labels["aKey"])
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
|
@ -1448,10 +1448,10 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
|
|||
closer, cdClient := fixture.ArgoCDClientset.NewApplicationClientOrDie()
|
||||
defer io.Close(closer)
|
||||
|
||||
deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deploymentResource, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
logs, err := cdClient.PodLogs(context.Background(), &applicationpkg.ApplicationPodLogsQuery{
|
||||
logs, err := cdClient.PodLogs(t.Context(), &applicationpkg.ApplicationPodLogsQuery{
|
||||
Group: ptr.To("apps"),
|
||||
Kind: ptr.To("Deployment"),
|
||||
Name: &appName,
|
||||
|
|
@ -1467,7 +1467,7 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
|
|||
|
||||
expectedError := "Deployment apps guestbook-ui not found as part of application " + appName
|
||||
|
||||
_, err = cdClient.ListResourceEvents(context.Background(), &applicationpkg.ApplicationResourceEventsQuery{
|
||||
_, err = cdClient.ListResourceEvents(t.Context(), &applicationpkg.ApplicationResourceEventsQuery{
|
||||
Name: &appName,
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
ResourceNamespace: ptr.To(fixture.DeploymentNamespace()),
|
||||
|
|
@ -1475,7 +1475,7 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, fmt.Sprintf("%s not found as part of application %s", "guestbook-ui", appName))
|
||||
|
||||
_, err = cdClient.GetResource(context.Background(), &applicationpkg.ApplicationResourceRequest{
|
||||
_, err = cdClient.GetResource(t.Context(), &applicationpkg.ApplicationResourceRequest{
|
||||
Name: &appName,
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
Namespace: ptr.To(fixture.DeploymentNamespace()),
|
||||
|
|
@ -1485,7 +1485,7 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, expectedError)
|
||||
|
||||
_, err = cdClient.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
|
||||
_, err = cdClient.RunResourceAction(t.Context(), &applicationpkg.ResourceActionRunRequest{
|
||||
Name: &appName,
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
Namespace: ptr.To(fixture.DeploymentNamespace()),
|
||||
|
|
@ -1496,7 +1496,7 @@ func assertResourceActions(t *testing.T, appName string, successful bool) {
|
|||
})
|
||||
assertError(err, expectedError)
|
||||
|
||||
_, err = cdClient.DeleteResource(context.Background(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
_, err = cdClient.DeleteResource(t.Context(), &applicationpkg.ApplicationResourceDeleteRequest{
|
||||
Name: &appName,
|
||||
ResourceName: ptr.To("guestbook-ui"),
|
||||
Namespace: ptr.To(fixture.DeploymentNamespace()),
|
||||
|
|
@ -1561,7 +1561,7 @@ func TestPermissions(t *testing.T) {
|
|||
defer io.Close(closer)
|
||||
appName, appNs := argo.ParseFromQualifiedName(app.Name, "")
|
||||
fmt.Printf("APP NAME: %s\n", appName)
|
||||
tree, err := cdClient.ResourceTree(context.Background(), &applicationpkg.ResourcesQuery{ApplicationName: &appName, AppNamespace: &appNs})
|
||||
tree, err := cdClient.ResourceTree(t.Context(), &applicationpkg.ResourcesQuery{ApplicationName: &appName, AppNamespace: &appNs})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, tree.Nodes)
|
||||
assert.Empty(t, tree.OrphanedNodes)
|
||||
|
|
@ -1825,7 +1825,7 @@ func TestSelfManagedApps(t *testing.T) {
|
|||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(a *Application) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Second*3)
|
||||
defer cancel()
|
||||
|
||||
reconciledCount := 0
|
||||
|
|
@ -1900,7 +1900,7 @@ func TestOrphanedResource(t *testing.T) {
|
|||
Expect(NoConditions()).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "orphaned-configmap",
|
||||
},
|
||||
|
|
@ -2006,7 +2006,7 @@ func TestNotPermittedResources(t *testing.T) {
|
|||
}
|
||||
defer func() {
|
||||
log.Infof("Ingress 'sample-ingress' deleted from %s", fixture.TestNamespace())
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
require.NoError(t, fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Delete(t.Context(), "sample-ingress", metav1.DeleteOptions{}))
|
||||
}()
|
||||
|
||||
svc := &corev1.Service{
|
||||
|
|
@ -2035,8 +2035,8 @@ func TestNotPermittedResources(t *testing.T) {
|
|||
},
|
||||
}).
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Create(context.Background(), ingress, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Create(context.Background(), svc, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Create(t.Context(), ingress, metav1.CreateOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Create(t.Context(), svc, metav1.CreateOptions{}))
|
||||
}).
|
||||
Path(guestbookPath).
|
||||
When().
|
||||
|
|
@ -2061,8 +2061,8 @@ func TestNotPermittedResources(t *testing.T) {
|
|||
Expect(DoesNotExist())
|
||||
|
||||
// Make sure prohibited resources are not deleted during application deletion
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.NetworkingV1().Ingresses(fixture.TestNamespace()).Get(t.Context(), "sample-ingress", metav1.GetOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{}))
|
||||
}
|
||||
|
||||
func TestSyncWithInfos(t *testing.T) {
|
||||
|
|
@ -2099,7 +2099,7 @@ func TestCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) {
|
|||
CreateWithNoNameSpace().
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
app, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
app, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, app.Status.Conditions)
|
||||
})
|
||||
|
|
@ -2119,7 +2119,7 @@ func TestCreateAppWithNoNameSpaceWhenRequired(t *testing.T) {
|
|||
Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, updatedApp.Status.Conditions, 2)
|
||||
|
|
@ -2143,7 +2143,7 @@ func TestCreateAppWithNoNameSpaceWhenRequired2(t *testing.T) {
|
|||
Refresh(RefreshTypeNormal).
|
||||
Then().
|
||||
And(func(app *Application) {
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
|
||||
updatedApp, err := fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Get(t.Context(), app.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, updatedApp.Status.Conditions, 2)
|
||||
|
|
@ -2182,7 +2182,7 @@ func TestListResource(t *testing.T) {
|
|||
Expect(NoConditions()).
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "orphaned-configmap",
|
||||
},
|
||||
|
|
@ -2592,7 +2592,7 @@ func TestSwitchTrackingMethod(t *testing.T) {
|
|||
And(func() {
|
||||
// Add resource with tracking annotation. This should put the
|
||||
// application OutOfSync.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2608,7 +2608,7 @@ func TestSwitchTrackingMethod(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Delete resource to bring application back in sync
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(context.Background(), "other-configmap", metav1.DeleteOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(t.Context(), "other-configmap", metav1.DeleteOptions{}))
|
||||
}).
|
||||
Then().
|
||||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
|
|
@ -2626,7 +2626,7 @@ func TestSwitchTrackingMethod(t *testing.T) {
|
|||
// Add a resource with a tracking annotation. This should not
|
||||
// affect the application, because we now use the tracking method
|
||||
// "label".
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2643,7 +2643,7 @@ func TestSwitchTrackingMethod(t *testing.T) {
|
|||
And(func() {
|
||||
// Add a resource with the tracking label. The app should become
|
||||
// OutOfSync.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "extra-configmap",
|
||||
Labels: map[string]string{
|
||||
|
|
@ -2659,7 +2659,7 @@ func TestSwitchTrackingMethod(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Delete resource to bring application back in sync
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(context.Background(), "extra-configmap", metav1.DeleteOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(t.Context(), "extra-configmap", metav1.DeleteOptions{}))
|
||||
}).
|
||||
Then().
|
||||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
|
|
@ -2684,7 +2684,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
And(func() {
|
||||
// Add extra resource that carries the default tracking label
|
||||
// We expect the app to go out of sync.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Labels: map[string]string{
|
||||
|
|
@ -2700,7 +2700,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Delete resource to bring application back in sync
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(context.Background(), "other-configmap", metav1.DeleteOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(t.Context(), "other-configmap", metav1.DeleteOptions{}))
|
||||
}).
|
||||
Then().
|
||||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
|
|
@ -2718,7 +2718,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
And(func() {
|
||||
// Create resource with the new tracking label, the application
|
||||
// is expected to go out of sync
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Labels: map[string]string{
|
||||
|
|
@ -2734,7 +2734,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Delete resource to bring application back in sync
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(context.Background(), "other-configmap", metav1.DeleteOptions{}))
|
||||
errors.NewHandler(t).FailOnErr(nil, fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Delete(t.Context(), "other-configmap", metav1.DeleteOptions{}))
|
||||
}).
|
||||
Then().
|
||||
Expect(OperationPhaseIs(OperationSucceeded)).
|
||||
|
|
@ -2745,7 +2745,7 @@ func TestSwitchTrackingLabel(t *testing.T) {
|
|||
// Add extra resource that carries the default tracking label
|
||||
// We expect the app to stay in sync, because the configured
|
||||
// label is different.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Labels: map[string]string{
|
||||
|
|
@ -2778,7 +2778,7 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
And(func() {
|
||||
// Add a resource with an annotation that is not referencing the
|
||||
// resource.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "extra-configmap",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2796,14 +2796,14 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
Sync("--prune").
|
||||
And(func() {
|
||||
// The extra configmap must not be pruned, because it's not tracked
|
||||
cm, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Get(context.Background(), "extra-configmap", metav1.GetOptions{})
|
||||
cm, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Get(t.Context(), "extra-configmap", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "extra-configmap", cm.Name)
|
||||
}).
|
||||
And(func() {
|
||||
// Add a resource with an annotation that is self-referencing the
|
||||
// resource.
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(context.Background(), &corev1.ConfigMap{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "other-configmap",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2821,7 +2821,7 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
Sync("--prune").
|
||||
And(func() {
|
||||
// The extra configmap must be pruned now, because it's tracked
|
||||
cm, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Get(context.Background(), "other-configmap", metav1.GetOptions{})
|
||||
cm, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Get(t.Context(), "other-configmap", metav1.GetOptions{})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "", cm.Name)
|
||||
}).
|
||||
|
|
@ -2832,7 +2832,7 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Add a cluster-scoped resource that is not referencing itself
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.RbacV1().ClusterRoles().Create(context.Background(), &rbacv1.ClusterRole{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.RbacV1().ClusterRoles().Create(t.Context(), &rbacv1.ClusterRole{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "e2e-test-clusterrole",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2852,7 +2852,7 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
When().
|
||||
And(func() {
|
||||
// Add a cluster-scoped resource that is referencing itself
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.RbacV1().ClusterRoles().Create(context.Background(), &rbacv1.ClusterRole{
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.RbacV1().ClusterRoles().Create(t.Context(), &rbacv1.ClusterRole{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "e2e-other-clusterrole",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2873,7 +2873,7 @@ func TestAnnotationTrackingExtraResources(t *testing.T) {
|
|||
Sync("--prune").
|
||||
And(func() {
|
||||
// The extra configmap must be pruned now, because it's tracked and does not exist in git
|
||||
cr, err := fixture.KubeClientset.RbacV1().ClusterRoles().Get(context.Background(), "e2e-other-clusterrole", metav1.GetOptions{})
|
||||
cr, err := fixture.KubeClientset.RbacV1().ClusterRoles().Get(t.Context(), "e2e-other-clusterrole", metav1.GetOptions{})
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "", cr.Name)
|
||||
}).
|
||||
|
|
@ -2932,7 +2932,7 @@ func TestInstallationID(t *testing.T) {
|
|||
SetTrackingMethod(string(argo.TrackingMethodAnnotation)).
|
||||
And(func() {
|
||||
_, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(
|
||||
context.Background(), &corev1.ConfigMap{
|
||||
t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-configmap",
|
||||
Annotations: map[string]string{
|
||||
|
|
@ -2962,11 +2962,11 @@ func TestInstallationID(t *testing.T) {
|
|||
Expect(SyncStatusIs(SyncStatusCodeSynced)).
|
||||
And(func(app *Application) {
|
||||
require.Len(t, app.Status.Resources, 2)
|
||||
svc, err := fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
svc, err := fixture.KubeClientset.CoreV1().Services(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "test", svc.Annotations[common.AnnotationInstallationID])
|
||||
|
||||
deploy, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{})
|
||||
deploy, err := fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Get(t.Context(), "guestbook-ui", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "test", deploy.Annotations[common.AnnotationInstallationID])
|
||||
})
|
||||
|
|
@ -2977,7 +2977,7 @@ func TestDeletionConfirmation(t *testing.T) {
|
|||
ctx.
|
||||
And(func() {
|
||||
_, err := fixture.KubeClientset.CoreV1().ConfigMaps(fixture.DeploymentNamespace()).Create(
|
||||
context.Background(), &corev1.ConfigMap{
|
||||
t.Context(), &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-configmap",
|
||||
Labels: map[string]string{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/argoproj/gitops-engine/pkg/sync/common"
|
||||
|
|
@ -50,7 +49,7 @@ func TestAppCreationInOtherNamespace(t *testing.T) {
|
|||
When().
|
||||
// ensure that update replaces spec and merge labels and annotations
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).Patch(t.Context(),
|
||||
ctx.AppName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
CreateApp("--upsert").
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
|
@ -1464,7 +1463,7 @@ func TestGitGeneratorPrivateRepoWithTemplatedProjectAndProjectScopedRepo(t *test
|
|||
r := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
})
|
||||
all := r.FlushAll(context.Background())
|
||||
all := r.FlushAll(t.Context())
|
||||
require.NoError(t, all.Err())
|
||||
|
||||
generateExpectedApp := func(name string) v1alpha1.Application {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
|
@ -1766,7 +1765,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictOk(t *testing.T) {
|
|||
|
||||
Given(t).
|
||||
And(func() {
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(t.Context(), &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: fixture.TestNamespace(),
|
||||
Name: secretName,
|
||||
|
|
@ -1824,7 +1823,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictOk(t *testing.T) {
|
|||
},
|
||||
}).Then().Expect(ApplicationsExist([]v1alpha1.Application{expectedApp})).
|
||||
When().And(func() {
|
||||
err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(t.Context(), secretName, metav1.DeleteOptions{})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
|
@ -1871,7 +1870,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictKo(t *testing.T) {
|
|||
|
||||
Given(t).
|
||||
And(func() {
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(context.Background(), &corev1.Secret{
|
||||
_, err := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Create(t.Context(), &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: fixture.TestNamespace(),
|
||||
Name: secretName,
|
||||
|
|
@ -1935,7 +1934,7 @@ func TestSimpleSCMProviderGeneratorTokenRefStrictKo(t *testing.T) {
|
|||
output, err := fixture.RunCli("appset", "get", "simple-scm-provider-generator-strict-ko")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, output, fmt.Sprintf("scm provider: error fetching Github token: secret %s/%s is not a valid SCM creds secret", fixture.TestNamespace(), secretName))
|
||||
err2 := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(context.Background(), secretName, metav1.DeleteOptions{})
|
||||
err2 := utils.GetE2EFixtureK8sClient(t).KubeClientset.CoreV1().Secrets(fixture.TestNamespace()).Delete(t.Context(), secretName, metav1.DeleteOptions{})
|
||||
assert.NoError(t, err2)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
|||
Name: username,
|
||||
},
|
||||
}
|
||||
_, err := KubeClientset.CoreV1().Namespaces().Create(context.Background(), &ns, metav1.CreateOptions{})
|
||||
_, err := KubeClientset.CoreV1().Namespaces().Create(t.Context(), &ns, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a ServiceAccount in that Namespace, which will be used for the Argo CD Cluster SEcret
|
||||
|
|
@ -288,7 +288,7 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
|||
APIGroups: []string{"*"},
|
||||
}},
|
||||
}
|
||||
_, err = KubeClientset.RbacV1().Roles(role.Namespace).Create(context.Background(), &role, metav1.CreateOptions{})
|
||||
_, err = KubeClientset.RbacV1().Roles(role.Namespace).Create(t.Context(), &role, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Bind the Role with the ServiceAccount in the Namespace
|
||||
|
|
@ -308,14 +308,14 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
|||
Name: role.Name,
|
||||
},
|
||||
}
|
||||
_, err = KubeClientset.RbacV1().RoleBindings(roleBinding.Namespace).Create(context.Background(), &roleBinding, metav1.CreateOptions{})
|
||||
_, err = KubeClientset.RbacV1().RoleBindings(roleBinding.Namespace).Create(t.Context(), &roleBinding, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
var token string
|
||||
|
||||
// Attempting to patch the ServiceAccount can intermittently fail with 'failed to patch serviceaccount "(...)" with bearer token secret: Operation cannot be fulfilled on serviceaccounts "(...)": the object has been modified; please apply your changes to the latest version and try again'
|
||||
// We thus keep trying for up to 20 seconds.
|
||||
waitErr := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 20*time.Second, true, func(context.Context) (done bool, err error) {
|
||||
waitErr := wait.PollUntilContextTimeout(t.Context(), 1*time.Second, 20*time.Second, true, func(context.Context) (done bool, err error) {
|
||||
// Retrieve the bearer token from the ServiceAccount
|
||||
token, err = clusterauth.GetServiceAccountBearerToken(KubeClientset, ns.Name, serviceAccountName, time.Second*60)
|
||||
|
||||
|
|
@ -329,10 +329,10 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
|||
if clusterScopedSecrets {
|
||||
clusterRole, clusterRoleBinding := generateReadOnlyClusterRoleandBindingForServiceAccount(username, username)
|
||||
|
||||
_, err := KubeClientset.RbacV1().ClusterRoles().Create(context.Background(), &clusterRole, metav1.CreateOptions{})
|
||||
_, err := KubeClientset.RbacV1().ClusterRoles().Create(t.Context(), &clusterRole, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = KubeClientset.RbacV1().ClusterRoleBindings().Create(context.Background(), &clusterRoleBinding, metav1.CreateOptions{})
|
||||
_, err = KubeClientset.RbacV1().ClusterRoleBindings().Create(t.Context(), &clusterRoleBinding, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -365,7 +365,7 @@ func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecre
|
|||
string(jsonStringBytes), clusterResourcesField, namespacesField)
|
||||
|
||||
// Finally, create the Cluster secret in the Argo CD E2E namespace
|
||||
_, err = KubeClientset.CoreV1().Secrets(secret.Namespace).Create(context.Background(), &secret, metav1.CreateOptions{})
|
||||
_, err = KubeClientset.CoreV1().Secrets(secret.Namespace).Create(t.Context(), &secret, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package applicationsets
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
|
@ -136,7 +135,7 @@ func pods(t *testing.T, namespace string) (*corev1.PodList, error) {
|
|||
t.Helper()
|
||||
fixtureClient := utils.GetE2EFixtureK8sClient(t)
|
||||
|
||||
pods, err := fixtureClient.KubeClientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{})
|
||||
pods, err := fixtureClient.KubeClientset.CoreV1().Pods(namespace).List(t.Context(), metav1.ListOptions{})
|
||||
return pods, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,20 +121,20 @@ func EnsureCleanState(t *testing.T) {
|
|||
func() error {
|
||||
// kubectl delete secrets -l argocd.argoproj.io/secret-type=repository
|
||||
return fixtureClient.KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: common.LabelKeySecretType + "=" + common.LabelValueSecretTypeRepository})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l argocd.argoproj.io/secret-type=repo-creds
|
||||
return fixtureClient.KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: common.LabelKeySecretType + "=" + common.LabelValueSecretTypeRepoCreds})
|
||||
},
|
||||
func() error {
|
||||
// Delete the applicationset-e2e namespace, if it exists
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(context.Background(), ApplicationsResourcesNamespace, metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(t.Context(), ApplicationsResourcesNamespace, metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
if err != nil && !apierrors.IsNotFound(err) { // 'not found' error is expected
|
||||
return err
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ func EnsureCleanState(t *testing.T) {
|
|||
},
|
||||
func() error {
|
||||
// Delete the argocd-e2e-external namespace, if it exists
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(context.Background(), string(ArgoCDExternalNamespace), metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(t.Context(), string(ArgoCDExternalNamespace), metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
if err != nil && !apierrors.IsNotFound(err) { // 'not found' error is expected
|
||||
return err
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ func EnsureCleanState(t *testing.T) {
|
|||
},
|
||||
func() error {
|
||||
// Delete the argocd-e2e-external namespace, if it exists
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(context.Background(), string(ArgoCDExternalNamespace2), metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
err := fixtureClient.KubeClientset.CoreV1().Namespaces().Delete(t.Context(), string(ArgoCDExternalNamespace2), metav1.DeleteOptions{PropagationPolicy: &policy})
|
||||
if err != nil && !apierrors.IsNotFound(err) { // 'not found' error is expected
|
||||
return err
|
||||
}
|
||||
|
|
@ -159,16 +159,16 @@ func EnsureCleanState(t *testing.T) {
|
|||
// delete resources
|
||||
func() error {
|
||||
// kubectl delete applicationsets --all
|
||||
return fixtureClient.AppSetClientset.DeleteCollection(context.Background(), metav1.DeleteOptions{PropagationPolicy: &policy}, metav1.ListOptions{})
|
||||
return fixtureClient.AppSetClientset.DeleteCollection(t.Context(), metav1.DeleteOptions{PropagationPolicy: &policy}, metav1.ListOptions{})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete apps --all
|
||||
return fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).DeleteCollection(context.Background(), metav1.DeleteOptions{PropagationPolicy: &policy}, metav1.ListOptions{})
|
||||
return fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).DeleteCollection(t.Context(), metav1.DeleteOptions{PropagationPolicy: &policy}, metav1.ListOptions{})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l e2e.argoproj.io=true
|
||||
return fixtureClient.KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: TestingLabel + "=true"})
|
||||
},
|
||||
|
|
@ -177,7 +177,7 @@ func EnsureCleanState(t *testing.T) {
|
|||
// First we wait up to 30 seconds for all the ApplicationSets to delete, but we don't fail if they don't.
|
||||
// Why? We want to give Argo CD time to delete the Application's child resources, before we remove the finalizers below.
|
||||
_ = waitForSuccess(func() error {
|
||||
list, err := fixtureClient.AppSetClientset.List(context.Background(), metav1.ListOptions{})
|
||||
list, err := fixtureClient.AppSetClientset.List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -191,14 +191,14 @@ func EnsureCleanState(t *testing.T) {
|
|||
|
||||
// Remove finalizers from Argo CD Application resources in the namespace
|
||||
err := waitForSuccess(func() error {
|
||||
appList, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).List(context.Background(), metav1.ListOptions{})
|
||||
appList, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, app := range appList.Items {
|
||||
t.Log("Removing finalizer for: ", app.Name)
|
||||
app.Finalizers = []string{}
|
||||
_, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Update(context.TODO(), &app, metav1.UpdateOptions{})
|
||||
_, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Update(t.Context(), &app, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ func waitForExpectedClusterState(t *testing.T) error {
|
|||
|
||||
// Wait up to 60 seconds for all the ApplicationSets to delete
|
||||
if err := waitForSuccess(func() error {
|
||||
list, err := fixtureClient.AppSetClientset.List(context.Background(), metav1.ListOptions{})
|
||||
list, err := fixtureClient.AppSetClientset.List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ func waitForExpectedClusterState(t *testing.T) error {
|
|||
|
||||
// Wait up to 60 seconds for all the Applications to delete
|
||||
if err := waitForSuccess(func() error {
|
||||
appList, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).List(context.Background(), metav1.ListOptions{})
|
||||
appList, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -279,10 +279,10 @@ func waitForExpectedClusterState(t *testing.T) error {
|
|||
|
||||
func SetProjectSpec(t *testing.T, fixtureClient *E2EFixtureK8sClient, project string, spec v1alpha1.AppProjectSpec) {
|
||||
t.Helper()
|
||||
proj, err := fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Get(context.Background(), project, metav1.GetOptions{})
|
||||
proj, err := fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Get(t.Context(), project, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
proj.Spec = spec
|
||||
_, err = fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Update(context.Background(), proj, metav1.UpdateOptions{})
|
||||
_, err = fixtureClient.AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Update(t.Context(), proj, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -648,49 +648,49 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
func() error {
|
||||
// kubectl delete apps ...
|
||||
return AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete apps ...
|
||||
return AppClientset.ArgoprojV1alpha1().Applications(AppNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete appprojects --field-selector metadata.name!=default
|
||||
return AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{FieldSelector: "metadata.name!=default"})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l argocd.argoproj.io/secret-type=repo-config
|
||||
return KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: common.LabelKeySecretType + "=" + common.LabelValueSecretTypeRepository})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l argocd.argoproj.io/secret-type=repo-creds
|
||||
return KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: common.LabelKeySecretType + "=" + common.LabelValueSecretTypeRepoCreds})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l argocd.argoproj.io/secret-type=cluster
|
||||
return KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: common.LabelKeySecretType + "=" + common.LabelValueSecretTypeCluster})
|
||||
},
|
||||
func() error {
|
||||
// kubectl delete secrets -l e2e.argoproj.io=true
|
||||
return KubeClientset.CoreV1().Secrets(TestNamespace()).DeleteCollection(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.DeleteOptions{PropagationPolicy: &policy},
|
||||
metav1.ListOptions{LabelSelector: TestingLabel + "=true"})
|
||||
},
|
||||
|
|
@ -700,7 +700,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
func() error {
|
||||
// delete old namespaces which were created by tests
|
||||
namespaces, err := KubeClientset.CoreV1().Namespaces().List(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.ListOptions{
|
||||
LabelSelector: TestingLabel + "=true",
|
||||
FieldSelector: "status.phase=Active",
|
||||
|
|
@ -720,7 +720,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
}
|
||||
}
|
||||
|
||||
namespaces, err = KubeClientset.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
|
||||
namespaces, err = KubeClientset.CoreV1().Namespaces().List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -748,7 +748,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
func() error {
|
||||
// delete old ClusterRoles which were created by tests
|
||||
clusterRoles, err := KubeClientset.RbacV1().ClusterRoles().List(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
metav1.ListOptions{
|
||||
LabelSelector: fmt.Sprintf("%s=%s", TestingLabel, "true"),
|
||||
},
|
||||
|
|
@ -767,7 +767,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
}
|
||||
}
|
||||
|
||||
clusterRoles, err = KubeClientset.RbacV1().ClusterRoles().List(context.Background(), metav1.ListOptions{})
|
||||
clusterRoles, err = KubeClientset.RbacV1().ClusterRoles().List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -789,7 +789,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
},
|
||||
func() error {
|
||||
// delete old ClusterRoleBindings which were created by tests
|
||||
clusterRoleBindings, err := KubeClientset.RbacV1().ClusterRoleBindings().List(context.Background(), metav1.ListOptions{})
|
||||
clusterRoleBindings, err := KubeClientset.RbacV1().ClusterRoleBindings().List(t.Context(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -857,7 +857,7 @@ func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
|||
|
||||
// Create separate project for testing gpg signature verification
|
||||
_, err = AppClientset.ArgoprojV1alpha1().AppProjects(TestNamespace()).Create(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
&v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "gpg",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -50,7 +49,7 @@ func TestAPIServerGracefulRestart(t *testing.T) {
|
|||
defer closer.Close()
|
||||
}
|
||||
require.NoError(t, err)
|
||||
settings, err := settingsClient.Get(context.Background(), &settings.SettingsQuery{})
|
||||
settings, err := settingsClient.Get(t.Context(), &settings.SettingsQuery{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "http://test-api-server-graceful-restart", settings.URL)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -63,7 +62,7 @@ func TestPostDeleteHook(t *testing.T) {
|
|||
Then().
|
||||
Expect(DoesNotExist()).
|
||||
AndAction(func() {
|
||||
hooks, err := KubeClientset.CoreV1().Pods(DeploymentNamespace()).List(context.Background(), metav1.ListOptions{})
|
||||
hooks, err := KubeClientset.CoreV1().Pods(DeploymentNamespace()).List(t.Context(), metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, hooks.Items, 1)
|
||||
assert.Equal(t, "hook", hooks.Items[0].Name)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
|
@ -50,7 +49,7 @@ func TestKubectlMetrics(t *testing.T) {
|
|||
When().
|
||||
// ensure that update replaces spec and merge labels and annotations
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Patch(t.Context(),
|
||||
ctx.GetName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
|
||||
}).
|
||||
CreateApp("--upsert").
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
func assertProjHasEvent(t *testing.T, a *v1alpha1.AppProject, message string, reason string) {
|
||||
t.Helper()
|
||||
list, err := fixture.KubeClientset.CoreV1().Events(fixture.TestNamespace()).List(context.Background(), metav1.ListOptions{
|
||||
list, err := fixture.KubeClientset.CoreV1().Events(fixture.TestNamespace()).List(t.Context(), metav1.ListOptions{
|
||||
FieldSelector: fields.SelectorFromSet(map[string]string{
|
||||
"involvedObject.name": a.Name,
|
||||
"involvedObject.uid": string(a.UID),
|
||||
|
|
@ -53,7 +53,7 @@ func TestProjectCreation(t *testing.T) {
|
|||
"--orphaned-resources")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 2)
|
||||
|
|
@ -89,7 +89,7 @@ func TestProjectCreation(t *testing.T) {
|
|||
_, err = fixture.RunCliWithStdin(stdinString, false, "proj", "create",
|
||||
"-f", "-", "--upsert")
|
||||
require.NoError(t, err)
|
||||
proj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newDescription, proj.Spec.Description)
|
||||
}
|
||||
|
|
@ -99,13 +99,13 @@ func TestProjectDeletion(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "delete", projectName)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
assert.True(t, errors.IsNotFound(err))
|
||||
assertProjHasEvent(t, proj, "delete", argo.EventReasonResourceDeleted)
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ func TestSetProject(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "set", projectName,
|
||||
|
|
@ -125,7 +125,7 @@ func TestSetProject(t *testing.T) {
|
|||
"--orphaned-resources-warn=false")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 2)
|
||||
|
|
@ -147,7 +147,7 @@ func TestAddProjectDestination(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "Unable to create project")
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-destination", projectName,
|
||||
|
|
@ -174,7 +174,7 @@ func TestAddProjectDestination(t *testing.T) {
|
|||
)
|
||||
require.ErrorContains(t, err, "namespace has an invalid format, '!*'")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 1)
|
||||
|
|
@ -189,7 +189,7 @@ func TestAddProjectDestinationWithName(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "Unable to create project")
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-destination", projectName,
|
||||
|
|
@ -199,7 +199,7 @@ func TestAddProjectDestinationWithName(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err, "Unable to add project destination")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.Destinations, 1)
|
||||
|
|
@ -214,7 +214,7 @@ func TestRemoveProjectDestination(t *testing.T) {
|
|||
fixture.EnsureCleanState(t)
|
||||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(context.Background(), &v1alpha1.AppProject{
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(t.Context(), &v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: projectName},
|
||||
Spec: v1alpha1.AppProjectSpec{
|
||||
Destinations: []v1alpha1.ApplicationDestination{{
|
||||
|
|
@ -237,7 +237,7 @@ func TestRemoveProjectDestination(t *testing.T) {
|
|||
)
|
||||
require.ErrorContains(t, err, "does not exist")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err, "Unable to get project")
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Empty(t, proj.Spec.Destinations)
|
||||
|
|
@ -249,7 +249,7 @@ func TestAddProjectSource(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "Unable to create project")
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
|
|
@ -258,7 +258,7 @@ func TestAddProjectSource(t *testing.T) {
|
|||
_, err = fixture.RunCli("proj", "add-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.SourceRepos, 1)
|
||||
|
|
@ -270,7 +270,7 @@ func TestRemoveProjectSource(t *testing.T) {
|
|||
fixture.EnsureCleanState(t)
|
||||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(context.Background(), &v1alpha1.AppProject{
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(t.Context(), &v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: projectName},
|
||||
Spec: v1alpha1.AppProjectSpec{
|
||||
SourceRepos: []string{"https://github.com/argoproj/argo-cd.git"},
|
||||
|
|
@ -286,7 +286,7 @@ func TestRemoveProjectSource(t *testing.T) {
|
|||
_, err = fixture.RunCli("proj", "remove-source", projectName, "https://github.com/argoproj/argo-cd.git")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Empty(t, proj.Spec.SourceRepos)
|
||||
|
|
@ -316,7 +316,7 @@ func TestUseJWTToken(t *testing.T) {
|
|||
Project: projectName,
|
||||
},
|
||||
}
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(context.Background(), &v1alpha1.AppProject{
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(t.Context(), &v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: projectName},
|
||||
Spec: v1alpha1.AppProjectSpec{
|
||||
Destinations: []v1alpha1.ApplicationDestination{{
|
||||
|
|
@ -328,7 +328,7 @@ func TestUseJWTToken(t *testing.T) {
|
|||
}, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Create(context.Background(), testApp, metav1.CreateOptions{})
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).Create(t.Context(), testApp, metav1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = fixture.RunCli("proj", "role", "create", projectName, roleName)
|
||||
|
|
@ -355,7 +355,7 @@ func TestUseJWTToken(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
newProj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
newProj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, newProj.Status.JWTTokensByRole[roleName].Items, 1)
|
||||
assert.ElementsMatch(t, newProj.Status.JWTTokensByRole[roleName].Items, newProj.Spec.Roles[0].JWTTokens)
|
||||
|
|
@ -366,7 +366,7 @@ func TestUseJWTToken(t *testing.T) {
|
|||
|
||||
_, err = fixture.RunCli("proj", "role", "delete-token", projectName, roleName, strconv.FormatInt(newProj.Status.JWTTokensByRole[roleName].Items[0].IssuedAt, 10))
|
||||
require.NoError(t, err)
|
||||
newProj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
newProj, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, newProj.Status.JWTTokensByRole[roleName].Items)
|
||||
assert.Nil(t, newProj.Spec.Roles[0].JWTTokens)
|
||||
|
|
@ -377,7 +377,7 @@ func TestAddOrphanedIgnore(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "Unable to create project")
|
||||
|
||||
_, err = fixture.RunCli("proj", "add-orphaned-ignore", projectName,
|
||||
|
|
@ -396,7 +396,7 @@ func TestAddOrphanedIgnore(t *testing.T) {
|
|||
)
|
||||
require.ErrorContains(t, err, "already defined")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.OrphanedResources.Ignore, 1)
|
||||
|
|
@ -411,7 +411,7 @@ func TestRemoveOrphanedIgnore(t *testing.T) {
|
|||
fixture.EnsureCleanState(t)
|
||||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(context.Background(), &v1alpha1.AppProject{
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(t.Context(), &v1alpha1.AppProject{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: projectName},
|
||||
Spec: v1alpha1.AppProjectSpec{
|
||||
OrphanedResources: &v1alpha1.OrphanedResourcesMonitorSettings{
|
||||
|
|
@ -438,7 +438,7 @@ func TestRemoveOrphanedIgnore(t *testing.T) {
|
|||
)
|
||||
require.ErrorContains(t, err, "does not exist")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err, "Unable to get project")
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Empty(t, proj.Spec.OrphanedResources.Ignore)
|
||||
|
|
@ -525,7 +525,7 @@ func TestGetVirtualProjectNoMatch(t *testing.T) {
|
|||
"--orphaned-resources")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an app belongs to proj project
|
||||
|
|
@ -556,12 +556,12 @@ func TestGetVirtualProjectMatch(t *testing.T) {
|
|||
"--orphaned-resources")
|
||||
require.NoError(t, err)
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), 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(context.Background(), proj, metav1.UpdateOptions{})
|
||||
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(t.Context(), proj, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an app belongs to proj project
|
||||
|
|
@ -583,7 +583,7 @@ func TestAddProjectDestinationServiceAccount(t *testing.T) {
|
|||
|
||||
projectName := "proj-" + strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Create(
|
||||
context.Background(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
t.Context(), &v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: projectName}}, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "Unable to create project")
|
||||
|
||||
// Given, an existing project
|
||||
|
|
@ -758,7 +758,7 @@ func TestAddProjectDestinationServiceAccount(t *testing.T) {
|
|||
)
|
||||
require.ErrorContains(t, err, "namespace has an invalid format, '[[ech*'")
|
||||
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.Background(), projectName, metav1.GetOptions{})
|
||||
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(t.Context(), projectName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, projectName, proj.Name)
|
||||
assert.Len(t, proj.Spec.DestinationServiceAccounts, 3)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -26,7 +25,7 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
||||
|
||||
require.NoError(t, err)
|
||||
exists := false
|
||||
|
|
@ -41,7 +40,7 @@ func TestAddRemovePublicRepo(t *testing.T) {
|
|||
_, err = fixture.RunCli("repo", "rm", repoURL)
|
||||
require.NoError(t, err)
|
||||
|
||||
repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
repo, err = repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
||||
require.NoError(t, err)
|
||||
exists = false
|
||||
for i := range repo.Items {
|
||||
|
|
@ -69,7 +68,7 @@ func TestGetRepoWithInheritedCreds(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
_, err = repoClient.UpdateRepository(context.Background(), &repositorypkg.RepoUpdateRequest{
|
||||
_, err = repoClient.UpdateRepository(t.Context(), &repositorypkg.RepoUpdateRequest{
|
||||
Repo: &v1alpha1.Repository{
|
||||
Repo: repoURL,
|
||||
},
|
||||
|
|
@ -115,7 +114,7 @@ func TestAddRemoveHelmRepo(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
||||
|
||||
require.NoError(t, err)
|
||||
exists := false
|
||||
|
|
@ -130,7 +129,7 @@ func TestAddRemoveHelmRepo(t *testing.T) {
|
|||
_, err = fixture.RunCli("repo", "rm", fixture.RepoURL(fixture.RepoURLTypeHelm))
|
||||
require.NoError(t, err)
|
||||
|
||||
repo, err = repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
repo, err = repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
||||
require.NoError(t, err)
|
||||
exists = false
|
||||
for i := range repo.Items {
|
||||
|
|
@ -161,7 +160,7 @@ func TestAddHelmRepoInsecureSkipVerify(t *testing.T) {
|
|||
|
||||
defer argoio.Close(conn)
|
||||
|
||||
repo, err := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
|
||||
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -74,7 +73,7 @@ func TestSyncWithStatusIgnored(t *testing.T) {
|
|||
// app should remain synced if k8s change detected
|
||||
When().
|
||||
And(func() {
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(),
|
||||
errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(),
|
||||
"guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/status/observedGeneration", "value": 2 }]`), metav1.PatchOptions{}))
|
||||
}).
|
||||
Then().
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -200,7 +199,7 @@ func TestSyncWithValidSAButDisallowedDestination(t *testing.T) {
|
|||
// Patch destination to disallow target destination namespace
|
||||
patch := []byte(fmt.Sprintf(`{"spec": {"destinations": [{"namespace": "%s"}]}}`, "!"+fixture.DeploymentNamespace()))
|
||||
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Patch(context.Background(), projectName, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
_, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Patch(t.Context(), projectName, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
require.NoError(t, err)
|
||||
}).
|
||||
Refresh(v1alpha1.RefreshTypeNormal).
|
||||
|
|
|
|||
|
|
@ -79,26 +79,7 @@ func copySingleFile(src string, dest string, mode os.FileInfo) error {
|
|||
|
||||
// CreateSymlink creates a symlink with name linkName to file destName in
|
||||
// workingDir
|
||||
func CreateSymlink(t *testing.T, workingDir, destName, linkName string) error {
|
||||
func CreateSymlink(t *testing.T, destName, linkName string) error {
|
||||
t.Helper()
|
||||
oldWorkingDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if workingDir != "" {
|
||||
err = os.Chdir(workingDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := os.Chdir(oldWorkingDir); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
err = os.Symlink(destName, linkName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Symlink(destName, linkName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
|
||||
|
|
@ -11,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDiscover(t *testing.T) {
|
||||
apps, err := Discover(context.Background(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
apps, err := Discover(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, map[string]string{
|
||||
"foo": "Kustomize",
|
||||
|
|
@ -20,15 +19,15 @@ func TestDiscover(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAppType(t *testing.T) {
|
||||
appType, err := AppType(context.Background(), "./testdata/foo", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Kustomize", appType)
|
||||
|
||||
appType, err = AppType(context.Background(), "./testdata/baz", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Helm", appType)
|
||||
|
||||
appType, err = AppType(context.Background(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
appType, err = AppType(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Directory", appType)
|
||||
}
|
||||
|
|
@ -38,15 +37,15 @@ func TestAppType_Disabled(t *testing.T) {
|
|||
string(v1alpha1.ApplicationSourceTypeKustomize): false,
|
||||
string(v1alpha1.ApplicationSourceTypeHelm): false,
|
||||
}
|
||||
appType, err := AppType(context.Background(), "./testdata/foo", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Directory", appType)
|
||||
|
||||
appType, err = AppType(context.Background(), "./testdata/baz", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Directory", appType)
|
||||
|
||||
appType, err = AppType(context.Background(), "./testdata", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
appType, err = AppType(t.Context(), "./testdata", "./testdata", enableManifestGeneration, []string{}, []string{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Directory", appType)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,9 +86,15 @@ func TestBadSymlinks3(t *testing.T) {
|
|||
// No absolute symlinks allowed
|
||||
func TestAbsSymlink(t *testing.T) {
|
||||
const testDir = "./testdata/abslink"
|
||||
require.NoError(t, fileutil.CreateSymlink(t, testDir, "/somethingbad", "abslink"))
|
||||
defer os.Remove(path.Join(testDir, "abslink"))
|
||||
err := CheckOutOfBoundsSymlinks(testDir)
|
||||
wd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(path.Join(testDir, "abslink"))
|
||||
})
|
||||
t.Chdir(testDir)
|
||||
require.NoError(t, fileutil.CreateSymlink(t, "/somethingbad", "abslink"))
|
||||
t.Chdir(wd)
|
||||
err = CheckOutOfBoundsSymlinks(testDir)
|
||||
var oobError *OutOfBoundsSymlinkError
|
||||
require.ErrorAs(t, err, &oobError)
|
||||
assert.Equal(t, "abslink", oobError.File)
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ func ValidateRepo(
|
|||
return nil, fmt.Errorf("error getting permitted repo creds: %w", err)
|
||||
}
|
||||
|
||||
destCluster, err := GetDestinationCluster(context.Background(), spec.Destination, db)
|
||||
destCluster, err := GetDestinationCluster(ctx, spec.Destination, db)
|
||||
if err != nil {
|
||||
conditions = append(conditions, argoappv1.ApplicationCondition{
|
||||
Type: argoappv1.ApplicationConditionInvalidSpecError,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func TestGetAppProjectWithNoProjDefined(t *testing.T) {
|
|||
testApp.Name = "test-app"
|
||||
testApp.Namespace = namespace
|
||||
appClientset := appclientset.NewSimpleClientset(testProj)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
indexers := cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
|
||||
informer := v1alpha1.NewAppProjectInformer(appClientset, namespace, 0, indexers)
|
||||
|
|
@ -79,7 +79,7 @@ func TestGetAppProjectWithNoProjDefined(t *testing.T) {
|
|||
cache.WaitForCacheSync(ctx.Done(), informer.HasSynced)
|
||||
|
||||
kubeClient := fake.NewClientset(&cm)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClient, test.FakeArgoCDNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeClient, test.FakeArgoCDNamespace)
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeClient)
|
||||
proj, err := GetAppProject(ctx, &testApp, applisters.NewAppProjectLister(informer.GetIndexer()), namespace, settingsMgr, argoDB)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -297,7 +297,7 @@ func TestNilOutZerValueAppSources(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestValidatePermissionsEmptyDestination(t *testing.T) {
|
||||
conditions, err := ValidatePermissions(context.Background(), &argoappv1.ApplicationSpec{
|
||||
conditions, err := ValidatePermissions(t.Context(), &argoappv1.ApplicationSpec{
|
||||
Source: &argoappv1.ApplicationSource{RepoURL: "https://github.com/argoproj/argo-cd", Path: "."},
|
||||
}, &argoappv1.AppProject{
|
||||
Spec: argoappv1.AppProjectSpec{
|
||||
|
|
@ -318,7 +318,7 @@ func TestValidateChartWithoutRevision(t *testing.T) {
|
|||
}
|
||||
cluster := &argoappv1.Cluster{Server: "https://kubernetes.default.svc"}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
db.On("GetCluster", ctx, appSpec.Destination.Server).Return(cluster, nil)
|
||||
|
||||
conditions, err := ValidatePermissions(ctx, appSpec, &argoappv1.AppProject{
|
||||
|
|
@ -389,7 +389,7 @@ func TestValidateRepo(t *testing.T) {
|
|||
|
||||
repoClient := &mocks.RepoServerServiceClient{}
|
||||
source := app.Spec.GetSource()
|
||||
repoClient.On("GetAppDetails", context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
repoClient.On("GetAppDetails", t.Context(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: repo,
|
||||
Source: &source,
|
||||
Repos: helmRepos,
|
||||
|
|
@ -399,7 +399,7 @@ func TestValidateRepo(t *testing.T) {
|
|||
}).Return(&apiclient.RepoAppDetailsResponse{}, nil)
|
||||
|
||||
repo.Type = "git"
|
||||
repoClient.On("TestRepository", context.Background(), &apiclient.TestRepositoryRequest{
|
||||
repoClient.On("TestRepository", t.Context(), &apiclient.TestRepositoryRequest{
|
||||
Repo: repo,
|
||||
}).Return(&apiclient.TestRepositoryResponse{
|
||||
VerifiedRepository: true,
|
||||
|
|
@ -409,14 +409,14 @@ func TestValidateRepo(t *testing.T) {
|
|||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
|
||||
db.On("GetRepository", context.Background(), app.Spec.Source.RepoURL, "").Return(repo, nil)
|
||||
db.On("ListHelmRepositories", context.Background()).Return(helmRepos, nil)
|
||||
db.On("GetCluster", context.Background(), app.Spec.Destination.Server).Return(cluster, nil)
|
||||
db.On("GetAllHelmRepositoryCredentials", context.Background()).Return(nil, nil)
|
||||
db.On("GetRepository", t.Context(), app.Spec.Source.RepoURL, "").Return(repo, nil)
|
||||
db.On("ListHelmRepositories", t.Context()).Return(helmRepos, nil)
|
||||
db.On("GetCluster", t.Context(), app.Spec.Destination.Server).Return(cluster, nil)
|
||||
db.On("GetAllHelmRepositoryCredentials", t.Context()).Return(nil, nil)
|
||||
|
||||
var receivedRequest *apiclient.ManifestRequest
|
||||
|
||||
repoClient.On("GenerateManifest", context.Background(), mock.MatchedBy(func(req *apiclient.ManifestRequest) bool {
|
||||
repoClient.On("GenerateManifest", t.Context(), mock.MatchedBy(func(req *apiclient.ManifestRequest) bool {
|
||||
receivedRequest = req
|
||||
return true
|
||||
})).Return(nil, nil)
|
||||
|
|
@ -446,9 +446,9 @@ func TestValidateRepo(t *testing.T) {
|
|||
}
|
||||
|
||||
kubeClient := fake.NewClientset(&cm)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClient, test.FakeArgoCDNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeClient, test.FakeArgoCDNamespace)
|
||||
|
||||
conditions, err := ValidateRepo(context.Background(), app, repoClientSet, db, &kubetest.MockKubectlCmd{Version: kubeVersion, APIResources: apiResources}, proj, settingsMgr)
|
||||
conditions, err := ValidateRepo(t.Context(), app, repoClientSet, db, &kubetest.MockKubectlCmd{Version: kubeVersion, APIResources: apiResources}, proj, settingsMgr)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, conditions)
|
||||
|
|
@ -636,7 +636,7 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
proj := argoappv1.AppProject{}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Equal(t, argoappv1.ApplicationConditionInvalidSpecError, conditions[0].Type)
|
||||
|
|
@ -653,7 +653,7 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
proj := argoappv1.AppProject{}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Equal(t, argoappv1.ApplicationConditionInvalidSpecError, conditions[0].Type)
|
||||
|
|
@ -670,7 +670,7 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
proj := argoappv1.AppProject{}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Equal(t, argoappv1.ApplicationConditionInvalidSpecError, conditions[0].Type)
|
||||
|
|
@ -703,8 +703,8 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
cluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "test"}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetCluster", t.Context(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "application repo http://some/where is not permitted")
|
||||
|
|
@ -736,8 +736,8 @@ func TestValidatePermissions(t *testing.T) {
|
|||
}
|
||||
cluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "test"}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetCluster", t.Context(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "application destination")
|
||||
|
|
@ -768,8 +768,8 @@ func TestValidatePermissions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(nil, status.Errorf(codes.NotFound, "Cluster does not exist"))
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetCluster", t.Context(), spec.Destination.Server).Return(nil, status.Errorf(codes.NotFound, "Cluster does not exist"))
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "Cluster does not exist")
|
||||
|
|
@ -800,8 +800,8 @@ func TestValidatePermissions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetClusterServersByName", context.Background(), "does-not-exist").Return(nil, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetClusterServersByName", t.Context(), "does-not-exist").Return(nil, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "there are no clusters with this name: does-not-exist")
|
||||
|
|
@ -832,8 +832,8 @@ func TestValidatePermissions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(nil, errors.New("Unknown error occurred"))
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetCluster", t.Context(), spec.Destination.Server).Return(nil, errors.New("Unknown error occurred"))
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "Unknown error occurred")
|
||||
|
|
@ -868,9 +868,9 @@ func TestValidatePermissions(t *testing.T) {
|
|||
Name: "does-exist",
|
||||
Server: "https://127.0.0.1:6443",
|
||||
}
|
||||
db.On("GetClusterServersByName", context.Background(), "does-exist").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", context.Background(), "https://127.0.0.1:6443").Return(&cluster, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetClusterServersByName", t.Context(), "does-exist").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", t.Context(), "https://127.0.0.1:6443").Return(&cluster, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, conditions)
|
||||
})
|
||||
|
|
@ -934,9 +934,9 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
|
||||
expectedCluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443"}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), "https://127.0.0.1:6443").Return(expectedCluster, nil)
|
||||
db.On("GetCluster", t.Context(), "https://127.0.0.1:6443").Return(expectedCluster, nil)
|
||||
|
||||
destCluster, err := GetDestinationCluster(context.Background(), dest, db)
|
||||
destCluster, err := GetDestinationCluster(t.Context(), dest, db)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, expectedCluster)
|
||||
assert.Equal(t, expectedCluster, destCluster)
|
||||
|
|
@ -948,10 +948,10 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetClusterServersByName", context.Background(), "minikube").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", context.Background(), "https://127.0.0.1:6443").Return(&argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "minikube"}, nil)
|
||||
db.On("GetClusterServersByName", t.Context(), "minikube").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", t.Context(), "https://127.0.0.1:6443").Return(&argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "minikube"}, nil)
|
||||
|
||||
destCluster, err := GetDestinationCluster(context.Background(), dest, db)
|
||||
destCluster, err := GetDestinationCluster(t.Context(), dest, db)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://127.0.0.1:6443", destCluster.Server)
|
||||
})
|
||||
|
|
@ -963,7 +963,7 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
Namespace: "default",
|
||||
}
|
||||
|
||||
_, err := GetDestinationCluster(context.Background(), dest, nil)
|
||||
_, err := GetDestinationCluster(t.Context(), dest, nil)
|
||||
assert.EqualError(t, err, "application destination can't have both name and server defined: minikube https://127.0.0.1:6443")
|
||||
})
|
||||
|
||||
|
|
@ -973,9 +973,9 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetClusterServersByName", context.Background(), mock.Anything).Return(nil, errors.New("an error occurred"))
|
||||
db.On("GetClusterServersByName", t.Context(), mock.Anything).Return(nil, errors.New("an error occurred"))
|
||||
|
||||
_, err := GetDestinationCluster(context.Background(), dest, db)
|
||||
_, err := GetDestinationCluster(t.Context(), dest, db)
|
||||
require.ErrorContains(t, err, "an error occurred")
|
||||
})
|
||||
|
||||
|
|
@ -985,9 +985,9 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetClusterServersByName", context.Background(), "minikube").Return(nil, nil)
|
||||
db.On("GetClusterServersByName", t.Context(), "minikube").Return(nil, nil)
|
||||
|
||||
_, err := GetDestinationCluster(context.Background(), dest, db)
|
||||
_, err := GetDestinationCluster(t.Context(), dest, db)
|
||||
assert.EqualError(t, err, "there are no clusters with this name: minikube")
|
||||
})
|
||||
|
||||
|
|
@ -997,9 +997,9 @@ func TestGetDestinationCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetClusterServersByName", context.Background(), "dind").Return([]string{"https://127.0.0.1:2443", "https://127.0.0.1:8443"}, nil)
|
||||
db.On("GetClusterServersByName", t.Context(), "dind").Return([]string{"https://127.0.0.1:2443", "https://127.0.0.1:8443"}, nil)
|
||||
|
||||
_, err := GetDestinationCluster(context.Background(), dest, db)
|
||||
_, err := GetDestinationCluster(t.Context(), dest, db)
|
||||
assert.EqualError(t, err, "there are 2 clusters with the same name: [https://127.0.0.1:2443 https://127.0.0.1:8443]")
|
||||
})
|
||||
}
|
||||
|
|
@ -1143,7 +1143,7 @@ func TestGetGlobalProjects(t *testing.T) {
|
|||
}
|
||||
|
||||
projClientset := appclientset.NewSimpleClientset(defaultX, defaultNonX, isX, isNoX)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
indexers := cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
|
||||
informer := v1alpha1.NewAppProjectInformer(projClientset, namespace, 0, indexers)
|
||||
|
|
@ -1151,7 +1151,7 @@ func TestGetGlobalProjects(t *testing.T) {
|
|||
cache.WaitForCacheSync(ctx.Done(), informer.HasSynced)
|
||||
|
||||
kubeClient := fake.NewSimpleClientset(&cm)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClient, test.FakeArgoCDNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeClient, test.FakeArgoCDNamespace)
|
||||
|
||||
projLister := applisters.NewAppProjectLister(informer.GetIndexer())
|
||||
|
||||
|
|
@ -1302,7 +1302,7 @@ func Test_GetRefSources(t *testing.T) {
|
|||
{RepoURL: "file://" + repoPath},
|
||||
})
|
||||
|
||||
refSources, err := GetRefSources(context.Background(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
refSources, err := GetRefSources(t.Context(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
return repo, nil
|
||||
}, []string{}, false)
|
||||
|
||||
|
|
@ -1322,7 +1322,7 @@ func Test_GetRefSources(t *testing.T) {
|
|||
{RepoURL: "file://" + repoPath},
|
||||
})
|
||||
|
||||
refSources, err := GetRefSources(context.Background(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
refSources, err := GetRefSources(t.Context(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
return nil, errors.New("repo does not exist")
|
||||
}, []string{}, false)
|
||||
|
||||
|
|
@ -1336,7 +1336,7 @@ func Test_GetRefSources(t *testing.T) {
|
|||
{RepoURL: "file://" + repoPath},
|
||||
})
|
||||
|
||||
refSources, err := GetRefSources(context.TODO(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
refSources, err := GetRefSources(t.Context(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
return nil, err
|
||||
}, []string{}, false)
|
||||
|
||||
|
|
@ -1350,7 +1350,7 @@ func Test_GetRefSources(t *testing.T) {
|
|||
{RepoURL: "file://does-not-exist", Ref: "source1"},
|
||||
})
|
||||
|
||||
refSources, err := GetRefSources(context.TODO(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
refSources, err := GetRefSources(t.Context(), argoSpec.Sources, argoSpec.Project, func(_ context.Context, _ string, _ string) (*argoappv1.Repository, error) {
|
||||
return nil, err
|
||||
}, []string{}, false)
|
||||
|
||||
|
|
@ -1369,7 +1369,7 @@ func TestValidatePermissionsMultipleSources(t *testing.T) {
|
|||
|
||||
proj := argoappv1.AppProject{}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Equal(t, argoappv1.ApplicationConditionInvalidSpecError, conditions[0].Type)
|
||||
|
|
@ -1389,7 +1389,7 @@ func TestValidatePermissionsMultipleSources(t *testing.T) {
|
|||
}
|
||||
proj := argoappv1.AppProject{}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Equal(t, argoappv1.ApplicationConditionInvalidSpecError, conditions[0].Type)
|
||||
|
|
@ -1424,8 +1424,8 @@ func TestValidatePermissionsMultipleSources(t *testing.T) {
|
|||
}
|
||||
cluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "test"}
|
||||
db := &dbmocks.ArgoDB{}
|
||||
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetCluster", t.Context(), spec.Destination.Server).Return(cluster, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, conditions, 1)
|
||||
assert.Contains(t, conditions[0].Message, "application repo http://some/where is not permitted")
|
||||
|
|
@ -1462,9 +1462,9 @@ func TestValidatePermissionsMultipleSources(t *testing.T) {
|
|||
Name: "does-exist",
|
||||
Server: "https://127.0.0.1:6443",
|
||||
}
|
||||
db.On("GetClusterServersByName", context.Background(), "does-exist").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", context.Background(), "https://127.0.0.1:6443").Return(&cluster, nil)
|
||||
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
|
||||
db.On("GetClusterServersByName", t.Context(), "does-exist").Return([]string{"https://127.0.0.1:6443"}, nil)
|
||||
db.On("GetCluster", t.Context(), "https://127.0.0.1:6443").Return(&cluster, nil)
|
||||
conditions, err := ValidatePermissions(t.Context(), &spec, &proj, db)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, conditions)
|
||||
})
|
||||
|
|
@ -1687,7 +1687,7 @@ func TestGetAppEventLabels(t *testing.T) {
|
|||
app.Namespace = test.FakeArgoCDNamespace
|
||||
app.Labels = tt.appLabels
|
||||
appClientset := appclientset.NewSimpleClientset(proj)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
indexers := cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
|
||||
informer := v1alpha1.NewAppProjectInformer(appClientset, test.FakeArgoCDNamespace, 0, indexers)
|
||||
|
|
@ -1695,7 +1695,7 @@ func TestGetAppEventLabels(t *testing.T) {
|
|||
cache.WaitForCacheSync(ctx.Done(), informer.HasSynced)
|
||||
|
||||
kubeClient := fake.NewSimpleClientset(&cm)
|
||||
settingsMgr := settings.NewSettingsManager(context.Background(), kubeClient, test.FakeArgoCDNamespace)
|
||||
settingsMgr := settings.NewSettingsManager(t.Context(), kubeClient, test.FakeArgoCDNamespace)
|
||||
argoDB := db.NewDB("default", settingsMgr, kubeClient)
|
||||
|
||||
eventLabels := GetAppEventLabels(ctx, &app, applisters.NewAppProjectLister(informer.GetIndexer()), test.FakeArgoCDNamespace, settingsMgr, argoDB)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestWithEarlierDeadline_NoDeadline(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
bufferedCtx, cancel := buffered_context.WithEarlierDeadline(ctx, 100*time.Millisecond)
|
||||
defer cancel()
|
||||
|
|
@ -23,7 +23,7 @@ func TestWithEarlierDeadline_NoDeadline(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWithEarlierDeadline_WithDeadline(t *testing.T) {
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now())
|
||||
ctx, cancel := context.WithDeadline(t.Context(), time.Now())
|
||||
defer cancel()
|
||||
|
||||
buffer := 100 * time.Millisecond
|
||||
|
|
|
|||
3
util/cache/redis_test.go
vendored
3
util/cache/redis_test.go
vendored
|
|
@ -3,7 +3,6 @@ package cache
|
|||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"io"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
|
@ -108,7 +107,7 @@ func TestRedisSetCacheCompressed(t *testing.T) {
|
|||
testValue := "my-value"
|
||||
require.NoError(t, client.Set(&Item{Key: "my-key", Object: testValue}))
|
||||
|
||||
compressedData, err := redisClient.Get(context.Background(), "my-key.gz").Bytes()
|
||||
compressedData, err := redisClient.Get(t.Context(), "my-key.gz").Bytes()
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Greater(t, len(compressedData), len([]byte(testValue)), "compressed data is bigger than uncompressed")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package clusterauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -83,7 +82,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
cs := fake.NewClientset(ns)
|
||||
err := CreateServiceAccount(cs, "argocd-manager", "kube-system")
|
||||
require.NoError(t, err)
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("kube-system").Get(context.Background(), "argocd-manager", metav1.GetOptions{})
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("kube-system").Get(t.Context(), "argocd-manager", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, rsa)
|
||||
})
|
||||
|
|
@ -92,7 +91,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
cs := fake.NewClientset(ns, sa)
|
||||
err := CreateServiceAccount(cs, "argocd-manager", "kube-system")
|
||||
require.NoError(t, err)
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("kube-system").Get(context.Background(), "argocd-manager", metav1.GetOptions{})
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("kube-system").Get(t.Context(), "argocd-manager", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, rsa)
|
||||
})
|
||||
|
|
@ -101,7 +100,7 @@ func TestCreateServiceAccount(t *testing.T) {
|
|||
cs := fake.NewClientset()
|
||||
err := CreateServiceAccount(cs, "argocd-manager", "invalid")
|
||||
require.NoError(t, err)
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("invalid").Get(context.Background(), "argocd-manager", metav1.GetOptions{})
|
||||
rsa, err := cs.CoreV1().ServiceAccounts("invalid").Get(t.Context(), "argocd-manager", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, rsa)
|
||||
})
|
||||
|
|
@ -215,7 +214,7 @@ func TestRotateServiceAccountSecrets(t *testing.T) {
|
|||
|
||||
// Verify service account references new secret and old secret is deleted
|
||||
saClient := kubeclientset.CoreV1().ServiceAccounts(testClaims.Namespace)
|
||||
sa, err := saClient.Get(context.Background(), testClaims.ServiceAccountName, metav1.GetOptions{})
|
||||
sa, err := saClient.Get(t.Context(), testClaims.ServiceAccountName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []corev1.ObjectReference{
|
||||
{
|
||||
|
|
@ -223,7 +222,7 @@ func TestRotateServiceAccountSecrets(t *testing.T) {
|
|||
},
|
||||
}, sa.Secrets)
|
||||
secretsClient := kubeclientset.CoreV1().Secrets(testClaims.Namespace)
|
||||
_, err = secretsClient.Get(context.Background(), testClaims.SecretName, metav1.GetOptions{})
|
||||
_, err = secretsClient.Get(t.Context(), testClaims.SecretName, metav1.GetOptions{})
|
||||
assert.True(t, apierrors.IsNotFound(err))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ func TestReceiveApplicationStream(t *testing.T) {
|
|||
close(streamMock.messages)
|
||||
os.RemoveAll(workdir)
|
||||
}()
|
||||
go streamMock.sendFile(context.Background(), t, appDir, streamMock, []string{"env1", "env2"}, []string{"DUMMY.md", "dum*"})
|
||||
go streamMock.sendFile(t.Context(), t, appDir, streamMock, []string{"env1", "env2"}, []string{"DUMMY.md", "dum*"})
|
||||
|
||||
// when
|
||||
env, err := cmp.ReceiveRepoStream(context.Background(), streamMock, workdir, false)
|
||||
env, err := cmp.ReceiveRepoStream(t.Context(), streamMock, workdir, false)
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -288,12 +287,12 @@ func getCertClientset() *fake.Clientset {
|
|||
|
||||
func TestListCertificate(t *testing.T) {
|
||||
clientset := getCertClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
assert.NotNil(t, db)
|
||||
|
||||
// List all SSH known host entries from configuration.
|
||||
// Expected: List of 7 entries
|
||||
certList, err := db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err := db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "*",
|
||||
CertType: "ssh",
|
||||
})
|
||||
|
|
@ -307,7 +306,7 @@ func TestListCertificate(t *testing.T) {
|
|||
|
||||
// List all TLS certificates from configuration.
|
||||
// Expected: List of 3 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "*",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -317,7 +316,7 @@ func TestListCertificate(t *testing.T) {
|
|||
|
||||
// List all certificates using selector
|
||||
// Expected: List of 10 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "*",
|
||||
CertType: "*",
|
||||
})
|
||||
|
|
@ -327,14 +326,14 @@ func TestListCertificate(t *testing.T) {
|
|||
|
||||
// List all certificates using nil selector
|
||||
// Expected: List of 10 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), nil)
|
||||
certList, err = db.ListRepoCertificates(t.Context(), nil)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, certList)
|
||||
assert.Len(t, certList.Items, TestNumTLSCertificatesExpected+TestNumSSHKnownHostsExpected)
|
||||
|
||||
// List all certificates matching a host name pattern
|
||||
// Expected: List of 4 entries, all with servername gitlab.com
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "gitlab.com",
|
||||
CertType: "*",
|
||||
})
|
||||
|
|
@ -346,7 +345,7 @@ func TestListCertificate(t *testing.T) {
|
|||
}
|
||||
|
||||
// List all TLS certificates matching a host name pattern
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "gitlab.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -359,11 +358,11 @@ func TestListCertificate(t *testing.T) {
|
|||
|
||||
func TestCreateSSHKnownHostEntries(t *testing.T) {
|
||||
clientset := getCertClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
assert.NotNil(t, db)
|
||||
|
||||
// Valid known hosts entry
|
||||
certList, err := db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err := db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -377,7 +376,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
assert.Len(t, certList.Items, 1)
|
||||
|
||||
// Valid known hosts entry
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "[foo.example.com]:2222",
|
||||
|
|
@ -392,7 +391,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Invalid hostname
|
||||
// Result: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo..example.com",
|
||||
|
|
@ -406,7 +405,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Check if it really was added
|
||||
// Result: List of 1 entry
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "foo.example.com",
|
||||
CertType: "ssh",
|
||||
})
|
||||
|
|
@ -416,7 +415,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Existing cert, same data, no upsert
|
||||
// Result: no error, should return 0 added certificates
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -431,7 +430,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Existing cert, different data, no upsert
|
||||
// Result: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -444,7 +443,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
assert.Nil(t, certList)
|
||||
|
||||
// Existing cert, different data, upsert
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -459,7 +458,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Invalid known hosts entry, case 1: key sub type missing
|
||||
// Result: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "bar.example.com",
|
||||
|
|
@ -473,7 +472,7 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
// Invalid known hosts entry, case 2: invalid base64 data
|
||||
// Result: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "bar.example.com",
|
||||
|
|
@ -488,12 +487,12 @@ func TestCreateSSHKnownHostEntries(t *testing.T) {
|
|||
|
||||
func TestCreateTLSCertificates(t *testing.T) {
|
||||
clientset := getCertClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
assert.NotNil(t, db)
|
||||
|
||||
// Valid TLS certificate
|
||||
// Expected: List of 1 entry
|
||||
certList, err := db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err := db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -508,7 +507,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Invalid hostname
|
||||
// Result: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo..example",
|
||||
|
|
@ -522,7 +521,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Check if it really was added
|
||||
// Result: Return new certificate
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "foo.example.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -532,7 +531,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid TLS certificates, multiple PEMs in data
|
||||
// Expected: List of 2 entry
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "bar.example.com",
|
||||
|
|
@ -547,7 +546,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Check if it really was added
|
||||
// Result: Return new certificate
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "bar.example.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -557,7 +556,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid TLS certificate, existing cert, same data, no upsert
|
||||
// Expected: List of 0 entry
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -572,7 +571,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid TLS certificate, existing cert, different data, no upsert
|
||||
// Expected: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -586,7 +585,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid TLS certificate, existing cert, different data, upsert
|
||||
// Expected: List of 2 entries
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "foo.example.com",
|
||||
|
|
@ -601,7 +600,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Check if upsert was successful
|
||||
// Expected: List of 2 entries, matching hostnames & cert types
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "foo.example.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -615,7 +614,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Invalid PEM data, new cert
|
||||
// Expected: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "baz.example.com",
|
||||
|
|
@ -629,7 +628,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid PEM data, new cert, but invalid certificate
|
||||
// Expected: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "baz.example.com",
|
||||
|
|
@ -643,7 +642,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Invalid PEM data, existing cert, upsert
|
||||
// Expected: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "baz.example.com",
|
||||
|
|
@ -657,7 +656,7 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
// Valid PEM data, existing cert, but invalid certificate, upsert
|
||||
// Expected: Error
|
||||
certList, err = db.CreateRepoCertificate(context.Background(), &v1alpha1.RepositoryCertificateList{
|
||||
certList, err = db.CreateRepoCertificate(t.Context(), &v1alpha1.RepositoryCertificateList{
|
||||
Items: []v1alpha1.RepositoryCertificate{
|
||||
{
|
||||
ServerName: "baz.example.com",
|
||||
|
|
@ -672,12 +671,12 @@ func TestCreateTLSCertificates(t *testing.T) {
|
|||
|
||||
func TestRemoveSSHKnownHosts(t *testing.T) {
|
||||
clientset := getCertClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
assert.NotNil(t, db)
|
||||
|
||||
// Remove single SSH known hosts entry by hostname
|
||||
// Expected: List of 1 entry
|
||||
certList, err := db.RemoveRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err := db.RemoveRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "github.com",
|
||||
CertType: "ssh",
|
||||
})
|
||||
|
|
@ -687,7 +686,7 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
// Check whether entry was really removed
|
||||
// Expected: List of 0 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "github.com",
|
||||
CertType: "ssh",
|
||||
})
|
||||
|
|
@ -697,7 +696,7 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
// Remove single SSH known hosts entry by sub type
|
||||
// Expected: List of 1 entry
|
||||
certList, err = db.RemoveRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.RemoveRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
CertType: "ssh",
|
||||
CertSubType: "ssh-ed25519",
|
||||
})
|
||||
|
|
@ -707,7 +706,7 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
// Check whether entry was really removed
|
||||
// Expected: List of 0 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
CertType: "ssh",
|
||||
CertSubType: "ssh-ed25519",
|
||||
})
|
||||
|
|
@ -717,7 +716,7 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
// Remove all remaining SSH known hosts entries
|
||||
// Expected: List of 5 entry
|
||||
certList, err = db.RemoveRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.RemoveRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
CertType: "ssh",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -726,7 +725,7 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
// Check whether the entries were really removed
|
||||
// Expected: List of 0 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
CertType: "ssh",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -736,12 +735,12 @@ func TestRemoveSSHKnownHosts(t *testing.T) {
|
|||
|
||||
func TestRemoveTLSCertificates(t *testing.T) {
|
||||
clientset := getCertClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
assert.NotNil(t, db)
|
||||
|
||||
// Remove single TLS certificate entry by hostname
|
||||
// Expected: List of 1 entry
|
||||
certList, err := db.RemoveRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err := db.RemoveRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "gitlab.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -751,7 +750,7 @@ func TestRemoveTLSCertificates(t *testing.T) {
|
|||
|
||||
// Check whether entry was really removed
|
||||
// Expected: List of 0 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "gitlab.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -761,7 +760,7 @@ func TestRemoveTLSCertificates(t *testing.T) {
|
|||
|
||||
// Remove all TLS certificate entry for hostname
|
||||
// Expected: List of 2 entry
|
||||
certList, err = db.RemoveRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.RemoveRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "test.example.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
@ -771,7 +770,7 @@ func TestRemoveTLSCertificates(t *testing.T) {
|
|||
|
||||
// Check whether entries were really removed
|
||||
// Expected: List of 0 entries
|
||||
certList, err = db.ListRepoCertificates(context.Background(), &CertificateListSelector{
|
||||
certList, err = db.ListRepoCertificates(t.Context(), &CertificateListSelector{
|
||||
HostNamePattern: "test.example.com",
|
||||
CertType: "https",
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
|
@ -47,14 +46,14 @@ func TestWatchClusters_CreateRemoveCluster(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
completed := runWatchTest(t, db, []func(old *v1alpha1.Cluster, new *v1alpha1.Cluster){
|
||||
func(old *v1alpha1.Cluster, new *v1alpha1.Cluster) {
|
||||
assert.Nil(t, old)
|
||||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, new.Server)
|
||||
|
||||
_, err := db.CreateCluster(context.Background(), &v1alpha1.Cluster{
|
||||
_, err := db.CreateCluster(t.Context(), &v1alpha1.Cluster{
|
||||
Server: "https://minikube",
|
||||
Name: "minikube",
|
||||
})
|
||||
|
|
@ -65,7 +64,7 @@ func TestWatchClusters_CreateRemoveCluster(t *testing.T) {
|
|||
assert.Equal(t, "https://minikube", new.Server)
|
||||
assert.Equal(t, "minikube", new.Name)
|
||||
|
||||
assert.NoError(t, db.DeleteCluster(context.Background(), "https://minikube"))
|
||||
assert.NoError(t, db.DeleteCluster(t.Context(), "https://minikube"))
|
||||
},
|
||||
func(old *v1alpha1.Cluster, new *v1alpha1.Cluster) {
|
||||
assert.Nil(t, new)
|
||||
|
|
@ -103,14 +102,14 @@ func TestWatchClusters_LocalClusterModifications(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
completed := runWatchTest(t, db, []func(old *v1alpha1.Cluster, new *v1alpha1.Cluster){
|
||||
func(old *v1alpha1.Cluster, new *v1alpha1.Cluster) {
|
||||
assert.Nil(t, old)
|
||||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, new.Server)
|
||||
|
||||
_, err := db.CreateCluster(context.Background(), &v1alpha1.Cluster{
|
||||
_, err := db.CreateCluster(t.Context(), &v1alpha1.Cluster{
|
||||
Server: v1alpha1.KubernetesInternalAPIServerAddr,
|
||||
Name: "some name",
|
||||
})
|
||||
|
|
@ -121,7 +120,7 @@ func TestWatchClusters_LocalClusterModifications(t *testing.T) {
|
|||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, new.Server)
|
||||
assert.Equal(t, "some name", new.Name)
|
||||
|
||||
assert.NoError(t, db.DeleteCluster(context.Background(), v1alpha1.KubernetesInternalAPIServerAddr))
|
||||
assert.NoError(t, db.DeleteCluster(t.Context(), v1alpha1.KubernetesInternalAPIServerAddr))
|
||||
},
|
||||
func(_ *v1alpha1.Cluster, new *v1alpha1.Cluster) {
|
||||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, new.Server)
|
||||
|
|
@ -159,7 +158,7 @@ func TestWatchClusters_LocalClusterModificationsWhenDisabled(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubeclientset := fake.NewClientset(argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
completed := runWatchTest(t, db, []func(_ *v1alpha1.Cluster, _ *v1alpha1.Cluster){
|
||||
func(_ *v1alpha1.Cluster, _ *v1alpha1.Cluster) {
|
||||
|
|
|
|||
|
|
@ -184,17 +184,17 @@ func TestUpdateCluster(t *testing.T) {
|
|||
"config": []byte("{}"),
|
||||
},
|
||||
})
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
requestedAt := metav1.Now()
|
||||
_, err := db.UpdateCluster(context.Background(), &v1alpha1.Cluster{
|
||||
_, err := db.UpdateCluster(t.Context(), &v1alpha1.Cluster{
|
||||
Name: "test",
|
||||
Server: "http://mycluster",
|
||||
RefreshRequestedAt: &requestedAt,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
secret, err := kubeclientset.CoreV1().Secrets(fakeNamespace).Get(context.Background(), "mycluster", metav1.GetOptions{})
|
||||
secret, err := kubeclientset.CoreV1().Secrets(fakeNamespace).Get(t.Context(), "mycluster", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, secret.Annotations[v1alpha1.AnnotationKeyRefresh], requestedAt.Format(time.RFC3339))
|
||||
|
|
@ -214,9 +214,9 @@ func TestDeleteUnknownCluster(t *testing.T) {
|
|||
"name": []byte("mycluster"),
|
||||
},
|
||||
})
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
assert.EqualError(t, db.DeleteCluster(context.Background(), "http://unknown"), `rpc error: code = NotFound desc = cluster "http://unknown" not found`)
|
||||
assert.EqualError(t, db.DeleteCluster(t.Context(), "http://unknown"), `rpc error: code = NotFound desc = cluster "http://unknown" not found`)
|
||||
}
|
||||
|
||||
func TestRejectCreationForInClusterWhenDisabled(t *testing.T) {
|
||||
|
|
@ -244,9 +244,9 @@ func TestRejectCreationForInClusterWhenDisabled(t *testing.T) {
|
|||
},
|
||||
}
|
||||
kubeclientset := fake.NewClientset(argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
_, err := db.CreateCluster(context.Background(), &v1alpha1.Cluster{
|
||||
_, err := db.CreateCluster(t.Context(), &v1alpha1.Cluster{
|
||||
Server: v1alpha1.KubernetesInternalAPIServerAddr,
|
||||
Name: "incluster-name",
|
||||
})
|
||||
|
|
@ -255,7 +255,7 @@ func TestRejectCreationForInClusterWhenDisabled(t *testing.T) {
|
|||
|
||||
func runWatchTest(t *testing.T, db ArgoDB, actions []func(old *v1alpha1.Cluster, new *v1alpha1.Cluster)) (completed bool) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
timeout := time.Second * 5
|
||||
|
|
@ -360,10 +360,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("Valid external cluster", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithExternalClusterAddr, emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
cluster, err := db.GetCluster(context.TODO(), string(secretForServerWithExternalClusterAddr.Data["server"]))
|
||||
cluster, err := db.GetCluster(t.Context(), string(secretForServerWithExternalClusterAddr.Data["server"]))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(secretForServerWithExternalClusterAddr.Data["server"]), cluster.Server)
|
||||
assert.Equal(t, string(secretForServerWithExternalClusterAddr.Data["name"]), cluster.Name)
|
||||
|
|
@ -371,10 +371,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("invalid cluster", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
_, err := db.GetCluster(context.TODO(), "https://mycluster-does-not-exist")
|
||||
_, err := db.GetCluster(t.Context(), "https://mycluster-does-not-exist")
|
||||
require.Error(t, err)
|
||||
status, ok := status.FromError(err)
|
||||
assert.True(t, ok)
|
||||
|
|
@ -383,10 +383,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("in-cluster not configured", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
cluster, err := db.GetCluster(context.TODO(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
cluster, err := db.GetCluster(t.Context(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, cluster.Server)
|
||||
assert.Equal(t, "in-cluster", cluster.Name)
|
||||
|
|
@ -394,10 +394,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("in-cluster disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
_, err := db.GetCluster(context.TODO(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
_, err := db.GetCluster(t.Context(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
require.Error(t, err)
|
||||
status, ok := status.FromError(err)
|
||||
assert.True(t, ok)
|
||||
|
|
@ -406,10 +406,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("in-cluster configured", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithInClusterAddr, emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
cluster, err := db.GetCluster(context.TODO(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
cluster, err := db.GetCluster(t.Context(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, v1alpha1.KubernetesInternalAPIServerAddr, cluster.Server)
|
||||
assert.Equal(t, "in-cluster-renamed", cluster.Name)
|
||||
|
|
@ -417,10 +417,10 @@ func TestGetCluster(t *testing.T) {
|
|||
|
||||
t.Run("in-cluster configured and disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithInClusterAddr, argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
_, err := db.GetCluster(context.TODO(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
_, err := db.GetCluster(t.Context(), v1alpha1.KubernetesInternalAPIServerAddr)
|
||||
require.Error(t, err)
|
||||
status, ok := status.FromError(err)
|
||||
assert.True(t, ok)
|
||||
|
|
@ -504,30 +504,30 @@ func TestListClusters(t *testing.T) {
|
|||
|
||||
t.Run("Valid clusters", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithInClusterAddr, secretForServerWithExternalClusterAddr, emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
clusters, err := db.ListClusters(context.TODO())
|
||||
clusters, err := db.ListClusters(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, clusters.Items, 2)
|
||||
})
|
||||
|
||||
t.Run("Cluster list with invalid cluster", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithInClusterAddr, secretForServerWithExternalClusterAddr, invalidSecret, emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
clusters, err := db.ListClusters(context.TODO())
|
||||
clusters, err := db.ListClusters(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, clusters.Items, 2)
|
||||
})
|
||||
|
||||
t.Run("Implicit in-cluster secret", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithExternalClusterAddr, emptyArgoCDConfigMap, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
clusters, err := db.ListClusters(context.TODO())
|
||||
clusters, err := db.ListClusters(t.Context())
|
||||
require.NoError(t, err)
|
||||
// ListClusters() should have added an implicit in-cluster secret to the list
|
||||
assert.Len(t, clusters.Items, 2)
|
||||
|
|
@ -535,20 +535,20 @@ func TestListClusters(t *testing.T) {
|
|||
|
||||
t.Run("ListClusters() should not add the cluster with in-cluster server address since in-cluster is disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithInClusterAddr, argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
clusters, err := db.ListClusters(context.TODO())
|
||||
clusters, err := db.ListClusters(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, clusters.Items)
|
||||
})
|
||||
|
||||
t.Run("ListClusters() should add this cluster since it does not contain in-cluster server address even though in-cluster is disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(secretForServerWithExternalClusterAddr, argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace)
|
||||
settingsManager := settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace)
|
||||
db := NewDB(fakeNamespace, settingsManager, kubeclientset)
|
||||
|
||||
clusters, err := db.ListClusters(context.TODO())
|
||||
clusters, err := db.ListClusters(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, clusters.Items, 1)
|
||||
})
|
||||
|
|
@ -626,36 +626,36 @@ func TestGetClusterServersByName(t *testing.T) {
|
|||
}
|
||||
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDClusterSecret, argoCDSecret)
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(context.Background(), "my-cluster-name")
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(t.Context(), "my-cluster-name")
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []string{"https://my-cluster-server"}, servers)
|
||||
})
|
||||
t.Run("returns in-cluster", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecret)
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(context.Background(), "in-cluster")
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(t.Context(), "in-cluster")
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []string{v1alpha1.KubernetesInternalAPIServerAddr}, servers)
|
||||
})
|
||||
t.Run("does not return in-cluster when disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecret)
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(context.Background(), "in-cluster")
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(t.Context(), "in-cluster")
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, servers)
|
||||
})
|
||||
t.Run("returns in-cluster when configured", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(emptyArgoCDConfigMap, argoCDSecretInClusterConfigured, argoCDSecret)
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(context.Background(), "in-cluster-renamed")
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(t.Context(), "in-cluster-renamed")
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []string{v1alpha1.KubernetesInternalAPIServerAddr}, servers)
|
||||
})
|
||||
t.Run("does not return in-cluster when configured and disabled", func(t *testing.T) {
|
||||
kubeclientset := fake.NewClientset(argoCDConfigMapWithInClusterServerAddressDisabled, argoCDSecretInClusterConfigured, argoCDSecret)
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(context.Background(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(context.Background(), "in-cluster-renamed")
|
||||
db := NewDB(fakeNamespace, settings.NewSettingsManager(t.Context(), kubeclientset, fakeNamespace), kubeclientset)
|
||||
servers, err := db.GetClusterServersByName(t.Context(), "in-cluster-renamed")
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, servers)
|
||||
})
|
||||
|
|
@ -664,7 +664,7 @@ func TestGetClusterServersByName(t *testing.T) {
|
|||
// TestClusterRaceConditionClusterSecrets reproduces a race condition
|
||||
// on the cluster secrets. The test isn't asserting anything because
|
||||
// before the fix it would cause a panic from concurrent map iteration and map write
|
||||
func TestClusterRaceConditionClusterSecrets(_ *testing.T) {
|
||||
func TestClusterRaceConditionClusterSecrets(t *testing.T) {
|
||||
clusterSecret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "mycluster",
|
||||
|
|
@ -704,14 +704,15 @@ func TestClusterRaceConditionClusterSecrets(_ *testing.T) {
|
|||
},
|
||||
clusterSecret,
|
||||
)
|
||||
settingsManager := settings.NewSettingsManager(context.Background(), kubeClient, "default")
|
||||
ctx := t.Context()
|
||||
settingsManager := settings.NewSettingsManager(ctx, kubeClient, "default")
|
||||
db := NewDB("default", settingsManager, kubeClient)
|
||||
cluster, _ := SecretToCluster(clusterSecret)
|
||||
go func() {
|
||||
for {
|
||||
// create a copy so we dont act on the same argo cluster
|
||||
clusterCopy := cluster.DeepCopy()
|
||||
_, _ = db.UpdateCluster(context.Background(), clusterCopy)
|
||||
_, _ = db.UpdateCluster(ctx, clusterCopy)
|
||||
}
|
||||
}()
|
||||
// yes, we will take 15 seconds to run this test
|
||||
|
|
@ -719,7 +720,7 @@ func TestClusterRaceConditionClusterSecrets(_ *testing.T) {
|
|||
for i := 0; i < 30; i++ {
|
||||
// create a copy so we dont act on the same argo cluster
|
||||
clusterCopy := cluster.DeepCopy()
|
||||
_, _ = db.UpdateCluster(context.Background(), clusterCopy)
|
||||
_, _ = db.UpdateCluster(ctx, clusterCopy)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -50,9 +49,9 @@ func getClientset(objects ...runtime.Object) *fake.Clientset {
|
|||
|
||||
func TestCreateRepository(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
repo, err := db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
repo, err := db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
|
|
@ -60,7 +59,7 @@ func TestCreateRepository(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://github.com/argoproj/argocd-example-apps", repo.Repo)
|
||||
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), RepoURLToSecretName(repoSecretPrefix, repo.Repo, ""), metav1.GetOptions{})
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), RepoURLToSecretName(repoSecretPrefix, repo.Repo, ""), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, common.AnnotationValueManagedByArgoCD, secret.Annotations[common.AnnotationKeyManagedBy])
|
||||
|
|
@ -71,9 +70,9 @@ func TestCreateRepository(t *testing.T) {
|
|||
|
||||
func TestCreateProjectScopedRepository(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
repo, err := db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
repo, err := db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
|
|
@ -81,7 +80,7 @@ func TestCreateProjectScopedRepository(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
otherRepo, err := db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
otherRepo, err := db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "other-username",
|
||||
Password: "other-password",
|
||||
|
|
@ -89,7 +88,7 @@ func TestCreateProjectScopedRepository(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
_, err = db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "wrong-username",
|
||||
Password: "wrong-password",
|
||||
|
|
@ -98,7 +97,7 @@ func TestCreateProjectScopedRepository(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "https://github.com/argoproj/argocd-example-apps", repo.Repo)
|
||||
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), RepoURLToSecretName(repoSecretPrefix, repo.Repo, "test-project"), metav1.GetOptions{})
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), RepoURLToSecretName(repoSecretPrefix, repo.Repo, "test-project"), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, common.AnnotationValueManagedByArgoCD, secret.Annotations[common.AnnotationKeyManagedBy])
|
||||
|
|
@ -107,7 +106,7 @@ func TestCreateProjectScopedRepository(t *testing.T) {
|
|||
assert.Equal(t, "test-project", string(secret.Data[project]))
|
||||
assert.Empty(t, secret.Data[sshPrivateKey])
|
||||
|
||||
secret, err = clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), RepoURLToSecretName(repoSecretPrefix, otherRepo.Repo, "other-project"), metav1.GetOptions{})
|
||||
secret, err = clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), RepoURLToSecretName(repoSecretPrefix, otherRepo.Repo, "other-project"), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.AnnotationValueManagedByArgoCD, secret.Annotations[common.AnnotationKeyManagedBy])
|
||||
assert.Equal(t, "other-username", string(secret.Data[username]))
|
||||
|
|
@ -118,9 +117,9 @@ func TestCreateProjectScopedRepository(t *testing.T) {
|
|||
|
||||
func TestCreateRepoCredentials(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
creds, err := db.CreateRepositoryCredentials(context.Background(), &v1alpha1.RepoCreds{
|
||||
creds, err := db.CreateRepositoryCredentials(t.Context(), &v1alpha1.RepoCreds{
|
||||
URL: "https://github.com/argoproj/",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
|
|
@ -128,7 +127,7 @@ func TestCreateRepoCredentials(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
assert.Equal(t, "https://github.com/argoproj/", creds.URL)
|
||||
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), RepoURLToSecretName(credSecretPrefix, creds.URL, ""), metav1.GetOptions{})
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), RepoURLToSecretName(credSecretPrefix, creds.URL, ""), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, common.AnnotationValueManagedByArgoCD, secret.Annotations[common.AnnotationKeyManagedBy])
|
||||
|
|
@ -136,7 +135,7 @@ func TestCreateRepoCredentials(t *testing.T) {
|
|||
assert.Equal(t, "test-password", string(secret.Data[password]))
|
||||
assert.Empty(t, secret.Data[sshPrivateKey])
|
||||
|
||||
created, err := db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
created, err := db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argo-cd",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -146,7 +145,7 @@ func TestCreateRepoCredentials(t *testing.T) {
|
|||
// Just give it a little time to settle.
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
repo, err := db.GetRepository(context.Background(), created.Repo, "")
|
||||
repo, err := db.GetRepository(t.Context(), created.Repo, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "test-username", repo.Username)
|
||||
assert.Equal(t, "test-password", repo.Password)
|
||||
|
|
@ -154,8 +153,8 @@ func TestCreateRepoCredentials(t *testing.T) {
|
|||
|
||||
func TestGetRepositoryCredentials(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
_, err := db.CreateRepositoryCredentials(context.Background(), &v1alpha1.RepoCreds{
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
_, err := db.CreateRepositoryCredentials(t.Context(), &v1alpha1.RepoCreds{
|
||||
URL: "https://secured",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
|
|
@ -190,7 +189,7 @@ func TestGetRepositoryCredentials(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := db.GetRepositoryCredentials(context.TODO(), tt.repoURL)
|
||||
got, err := db.GetRepositoryCredentials(t.Context(), tt.repoURL)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
|
@ -200,16 +199,16 @@ func TestGetRepositoryCredentials(t *testing.T) {
|
|||
|
||||
func TestCreateExistingRepository(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
_, err := db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
_, err := db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = db.CreateRepository(context.Background(), &v1alpha1.Repository{
|
||||
_, err = db.CreateRepository(t.Context(), &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
Username: "test-username",
|
||||
Password: "test-password",
|
||||
|
|
@ -264,7 +263,7 @@ func TestGetRepository(t *testing.T) {
|
|||
"password": []byte("test-password"),
|
||||
},
|
||||
})
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -289,7 +288,7 @@ func TestGetRepository(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := db.GetRepository(context.TODO(), tt.repoURL, "")
|
||||
got, err := db.GetRepository(t.Context(), tt.repoURL, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
|
|
@ -299,14 +298,14 @@ func TestGetRepository(t *testing.T) {
|
|||
func TestCreateClusterSuccessful(t *testing.T) {
|
||||
server := "https://mycluster"
|
||||
clientset := getClientset()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
_, err := db.CreateCluster(context.Background(), &v1alpha1.Cluster{
|
||||
_, err := db.CreateCluster(t.Context(), &v1alpha1.Cluster{
|
||||
Server: server,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), "cluster-mycluster-3274446258", metav1.GetOptions{})
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), "cluster-mycluster-3274446258", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, server, string(secret.Data["server"]))
|
||||
|
|
@ -334,11 +333,11 @@ func TestDeleteClusterWithManagedSecret(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
err := db.DeleteCluster(context.Background(), clusterURL)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
err := db.DeleteCluster(t.Context(), clusterURL)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), clusterName, metav1.GetOptions{})
|
||||
_, err = clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), clusterName, metav1.GetOptions{})
|
||||
require.Error(t, err)
|
||||
|
||||
assert.True(t, errors.IsNotFound(err))
|
||||
|
|
@ -362,11 +361,11 @@ func TestDeleteClusterWithUnmanagedSecret(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
err := db.DeleteCluster(context.Background(), clusterURL)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
err := db.DeleteCluster(t.Context(), clusterURL)
|
||||
require.NoError(t, err)
|
||||
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(context.Background(), clusterName, metav1.GetOptions{})
|
||||
secret, err := clientset.CoreV1().Secrets(testNamespace).Get(t.Context(), clusterName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Empty(t, secret.Labels)
|
||||
|
|
@ -374,8 +373,8 @@ func TestDeleteClusterWithUnmanagedSecret(t *testing.T) {
|
|||
|
||||
func TestFuzzyEquivalence(t *testing.T) {
|
||||
clientset := getClientset()
|
||||
ctx := context.Background()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
ctx := t.Context()
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
|
||||
repo, err := db.CreateRepository(ctx, &v1alpha1.Repository{
|
||||
Repo: "https://github.com/argoproj/argocd-example-apps",
|
||||
|
|
@ -404,7 +403,7 @@ func TestGetApplicationControllerReplicas(t *testing.T) {
|
|||
clientset := getClientset()
|
||||
expectedReplicas := int32(2)
|
||||
t.Setenv(common.EnvControllerReplicas, "2")
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db := NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
replicas := db.GetApplicationControllerReplicas()
|
||||
assert.Equal(t, int(expectedReplicas), replicas)
|
||||
|
||||
|
|
@ -419,7 +418,7 @@ func TestGetApplicationControllerReplicas(t *testing.T) {
|
|||
},
|
||||
})
|
||||
t.Setenv(common.EnvControllerReplicas, "2")
|
||||
db = NewDB(testNamespace, settings.NewSettingsManager(context.Background(), clientset, testNamespace), clientset)
|
||||
db = NewDB(testNamespace, settings.NewSettingsManager(t.Context(), clientset, testNamespace), clientset)
|
||||
replicas = db.GetApplicationControllerReplicas()
|
||||
assert.Equal(t, int(expectedReplicas), replicas)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -143,60 +142,60 @@ func Test_ListConfiguredGPGPublicKeys(t *testing.T) {
|
|||
// Good case. Single key in input, right mapping to Key ID in CM
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMSingleGoodPubkey)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
if db == nil {
|
||||
panic("could not get database")
|
||||
}
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, keys, 1)
|
||||
}
|
||||
// Good case. No certificates in ConfigMap
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMEmpty)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
if db == nil {
|
||||
panic("could not get database")
|
||||
}
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, keys)
|
||||
}
|
||||
// Bad case. Single key in input, wrong mapping to Key ID in CM
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMSingleKeyWrongId)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
if db == nil {
|
||||
panic("could not get database")
|
||||
}
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.Error(t, err)
|
||||
assert.Empty(t, keys)
|
||||
}
|
||||
// Bad case. Garbage public key
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMGarbagePubkey)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
if db == nil {
|
||||
panic("could not get database")
|
||||
}
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.Error(t, err)
|
||||
assert.Empty(t, keys)
|
||||
}
|
||||
// Bad case. Garbage ConfigMap key in data
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMGarbageCMKey)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
if db == nil {
|
||||
panic("could not get database")
|
||||
}
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
keys, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.Error(t, err)
|
||||
assert.Empty(t, keys)
|
||||
}
|
||||
|
|
@ -206,11 +205,11 @@ func Test_AddGPGPublicKey(t *testing.T) {
|
|||
// Good case
|
||||
{
|
||||
clientset := getGPGKeysClientset(gpgCMEmpty)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
|
||||
// Key should be added
|
||||
new, skipped, err := db.AddGPGPublicKey(context.Background(), testdata.Github_asc)
|
||||
new, skipped, err := db.AddGPGPublicKey(t.Context(), testdata.Github_asc)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, new, 1)
|
||||
assert.Empty(t, skipped)
|
||||
|
|
@ -219,7 +218,7 @@ func Test_AddGPGPublicKey(t *testing.T) {
|
|||
assert.Len(t, cm.Data, 1)
|
||||
|
||||
// Same key should not be added, but skipped
|
||||
new, skipped, err = db.AddGPGPublicKey(context.Background(), testdata.Github_asc)
|
||||
new, skipped, err = db.AddGPGPublicKey(t.Context(), testdata.Github_asc)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, new)
|
||||
assert.Len(t, skipped, 1)
|
||||
|
|
@ -228,7 +227,7 @@ func Test_AddGPGPublicKey(t *testing.T) {
|
|||
assert.Len(t, cm.Data, 1)
|
||||
|
||||
// New keys should be added
|
||||
new, skipped, err = db.AddGPGPublicKey(context.Background(), testdata.Multi_asc)
|
||||
new, skipped, err = db.AddGPGPublicKey(t.Context(), testdata.Multi_asc)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, new, 2)
|
||||
assert.Empty(t, skipped)
|
||||
|
|
@ -237,7 +236,7 @@ func Test_AddGPGPublicKey(t *testing.T) {
|
|||
assert.Len(t, cm.Data, 3)
|
||||
|
||||
// Same new keys should be skipped
|
||||
new, skipped, err = db.AddGPGPublicKey(context.Background(), testdata.Multi_asc)
|
||||
new, skipped, err = db.AddGPGPublicKey(t.Context(), testdata.Multi_asc)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, new)
|
||||
assert.Len(t, skipped, 2)
|
||||
|
|
@ -246,7 +245,7 @@ func Test_AddGPGPublicKey(t *testing.T) {
|
|||
assert.Len(t, cm.Data, 3)
|
||||
|
||||
// Garbage input should result in error
|
||||
new, skipped, err = db.AddGPGPublicKey(context.Background(), testdata.Garbage_asc)
|
||||
new, skipped, err = db.AddGPGPublicKey(t.Context(), testdata.Garbage_asc)
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, new)
|
||||
assert.Nil(t, skipped)
|
||||
|
|
@ -261,43 +260,43 @@ func Test_DeleteGPGPublicKey(t *testing.T) {
|
|||
|
||||
t.Run("good case", func(t *testing.T) {
|
||||
clientset := getGPGKeysClientset(gpgCMMultiGoodPubkey)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
|
||||
// Key should be removed
|
||||
err := db.DeleteGPGPublicKey(context.Background(), "FDC79815400D88A9")
|
||||
err := db.DeleteGPGPublicKey(t.Context(), "FDC79815400D88A9")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Key should not exist anymore, therefore can't be deleted again
|
||||
err = db.DeleteGPGPublicKey(context.Background(), "FDC79815400D88A9")
|
||||
err = db.DeleteGPGPublicKey(t.Context(), "FDC79815400D88A9")
|
||||
require.Error(t, err)
|
||||
|
||||
// One key left in configuration
|
||||
n, err := db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
n, err := db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, n, 1)
|
||||
|
||||
// Key should be removed
|
||||
err = db.DeleteGPGPublicKey(context.Background(), "F7842A5CEAA9C0B1")
|
||||
err = db.DeleteGPGPublicKey(t.Context(), "F7842A5CEAA9C0B1")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Key should not exist anymore, therefore can't be deleted again
|
||||
err = db.DeleteGPGPublicKey(context.Background(), "F7842A5CEAA9C0B1")
|
||||
err = db.DeleteGPGPublicKey(t.Context(), "F7842A5CEAA9C0B1")
|
||||
require.Error(t, err)
|
||||
|
||||
// No key left in configuration
|
||||
n, err = db.ListConfiguredGPGPublicKeys(context.Background())
|
||||
n, err = db.ListConfiguredGPGPublicKeys(t.Context())
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, n)
|
||||
})
|
||||
|
||||
t.Run("bad case - empty ConfigMap", func(t *testing.T) {
|
||||
clientset := getGPGKeysClientset(gpgCMEmpty)
|
||||
settings := settings.NewSettingsManager(context.Background(), clientset, testNamespace)
|
||||
settings := settings.NewSettingsManager(t.Context(), clientset, testNamespace)
|
||||
db := NewDB(testNamespace, settings, clientset)
|
||||
|
||||
// Key should be removed
|
||||
err := db.DeleteGPGPublicKey(context.Background(), "F7842A5CEAA9C0B1")
|
||||
err := db.DeleteGPGPublicKey(t.Context(), "F7842A5CEAA9C0B1")
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue