Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Da Costa <[email protected]>
  • Loading branch information
dacofr committed Jul 8, 2024
1 parent 75f492e commit c1ad38b
Showing 1 changed file with 11 additions and 61 deletions.
72 changes: 11 additions & 61 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, c := range []struct {
// name is human-readable test name
name string
Expand Down Expand Up @@ -1119,9 +1116,6 @@ func TestRemoveFinalizerOnInvalidDestination_FinalizerTypes(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, c := range []struct {
// name is human-readable test name
name string
Expand Down Expand Up @@ -1241,9 +1235,6 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, c := range []struct {
// name is human-readable test name
name string
Expand Down Expand Up @@ -1397,9 +1388,6 @@ func TestRemoveOwnerReferencesOnDeleteAppSet(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, c := range []struct {
// name is human-readable test name
name string
Expand Down Expand Up @@ -1472,9 +1460,6 @@ func TestCreateApplications(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

testCases := []struct {
name string
appSet v1alpha1.ApplicationSet
Expand Down Expand Up @@ -1677,8 +1662,6 @@ func TestDeleteInCluster(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, c := range []struct {
// appSet is the application set on which the delete function is called
Expand Down Expand Up @@ -1831,8 +1814,6 @@ func TestGetMinRequeueAfter(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

client := fake.NewClientBuilder().WithScheme(scheme).Build()

Expand Down Expand Up @@ -1880,11 +1861,6 @@ func TestValidateGeneratedApplications(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

client := fake.NewClientBuilder().WithScheme(scheme).Build()

// Valid cluster
myCluster := v1alpha1.Cluster{
Server: "https://kubernetes.default.svc",
Expand All @@ -1911,6 +1887,8 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(myProject).Build()

// Test a subset of the validations that 'validateGeneratedApplications' performs
for _, cc := range []struct {
name string
Expand Down Expand Up @@ -2060,7 +2038,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
myCluster,
}}, nil)

argoObjs := []runtime.Object{myProject}
argoObjs := []runtime.Object{}
for _, app := range cc.apps {
argoObjs = append(argoObjs, &app)
}
Expand Down Expand Up @@ -2116,8 +2094,6 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

project := v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{Name: "good-project", Namespace: "argocd"},
Expand Down Expand Up @@ -2156,9 +2132,9 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {

kubeclientset := kubefake.NewSimpleClientset()
argoDBMock := dbmocks.ArgoDB{}
argoObjs := []runtime.Object{&project}
argoObjs := []runtime.Object{}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &project).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
badCluster := v1alpha1.Cluster{Server: "https://bad-cluster", Name: "bad-cluster"}
argoDBMock.On("GetCluster", mock.Anything, "https://good-cluster").Return(&goodCluster, nil)
Expand Down Expand Up @@ -2211,8 +2187,6 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

appSet := v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -2268,8 +2242,6 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

defaultProject := v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
Expand Down Expand Up @@ -2309,9 +2281,9 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp

kubeclientset := kubefake.NewSimpleClientset()
argoDBMock := dbmocks.ArgoDB{}
argoObjs := []runtime.Object{&defaultProject}
argoObjs := []runtime.Object{}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
argoDBMock.On("GetCluster", mock.Anything, "https://good-cluster").Return(&goodCluster, nil)
argoDBMock.On("ListClusters", mock.Anything).Return(&v1alpha1.ClusterList{Items: []v1alpha1.Cluster{
Expand Down Expand Up @@ -2432,8 +2404,6 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

defaultProject := v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
Expand Down Expand Up @@ -2473,9 +2443,9 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp

kubeclientset := kubefake.NewSimpleClientset()
argoDBMock := dbmocks.ArgoDB{}
argoObjs := []runtime.Object{&defaultProject}
argoObjs := []runtime.Object{}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
goodCluster := v1alpha1.Cluster{Server: "https://good-cluster", Name: "good-cluster"}
argoDBMock.On("GetCluster", mock.Anything, "https://good-cluster").Return(&goodCluster, nil)
argoDBMock.On("ListClusters", mock.Anything).Return(&v1alpha1.ClusterList{Items: []v1alpha1.Cluster{
Expand Down Expand Up @@ -2590,9 +2560,6 @@ func TestPolicies(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

defaultProject := v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "argocd"},
Spec: v1alpha1.AppProjectSpec{SourceRepos: []string{"*"}, Destinations: []v1alpha1.ApplicationDestination{{Namespace: "*", Server: "https://kubernetes.default.svc"}}},
Expand All @@ -2605,7 +2572,7 @@ func TestPolicies(t *testing.T) {
kubeclientset := kubefake.NewSimpleClientset()
argoDBMock := dbmocks.ArgoDB{}
argoDBMock.On("GetCluster", mock.Anything, "https://kubernetes.default.svc").Return(&myCluster, nil)
argoObjs := []runtime.Object{&defaultProject}
argoObjs := []runtime.Object{}

for _, c := range []struct {
name string
Expand Down Expand Up @@ -2677,7 +2644,7 @@ func TestPolicies(t *testing.T) {
},
}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()

r := ApplicationSetReconciler{
Client: client,
Expand Down Expand Up @@ -2760,8 +2727,6 @@ func TestSetApplicationSetApplicationStatus(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)
err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

kubeclientset := kubefake.NewSimpleClientset([]runtime.Object{}...)
argoDBMock := dbmocks.ArgoDB{}
Expand Down Expand Up @@ -2867,9 +2832,6 @@ func TestBuildAppDependencyList(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

client := fake.NewClientBuilder().WithScheme(scheme).Build()

for _, cc := range []struct {
Expand Down Expand Up @@ -3627,9 +3589,6 @@ func TestBuildAppSyncMap(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

client := fake.NewClientBuilder().WithScheme(scheme).Build()

for _, cc := range []struct {
Expand Down Expand Up @@ -4217,9 +4176,6 @@ func TestUpdateApplicationSetApplicationStatus(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, cc := range []struct {
name string
appSet v1alpha1.ApplicationSet
Expand Down Expand Up @@ -4950,9 +4906,6 @@ func TestUpdateApplicationSetApplicationStatusProgress(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, cc := range []struct {
name string
appSet v1alpha1.ApplicationSet
Expand Down Expand Up @@ -5701,9 +5654,6 @@ func TestUpdateResourceStatus(t *testing.T) {
err := v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

err = v1alpha1.AddToScheme(scheme)
require.NoError(t, err)

for _, cc := range []struct {
name string
appSet v1alpha1.ApplicationSet
Expand Down

0 comments on commit c1ad38b

Please sign in to comment.