diff --git a/applicationset/controllers/applicationset_controller_test.go b/applicationset/controllers/applicationset_controller_test.go index 7f3c26e4d3e0b..ec28e96d767e7 100644 --- a/applicationset/controllers/applicationset_controller_test.go +++ b/applicationset/controllers/applicationset_controller_test.go @@ -4,9 +4,7 @@ import ( "context" "encoding/json" "fmt" - "reflect" "strconv" - "strings" "testing" "time" @@ -1893,6 +1891,8 @@ func TestRequeueGeneratorFails(t *testing.T) { } func TestValidateGeneratedApplications(t *testing.T) { + t.Parallel() + scheme := runtime.NewScheme() err := v1alpha1.AddToScheme(scheme) require.NoError(t, err) @@ -1924,7 +1924,6 @@ func TestValidateGeneratedApplications(t *testing.T) { for _, cc := range []struct { name string apps []v1alpha1.Application - expectedErrors []string validationErrors map[int]error }{ { @@ -1947,7 +1946,6 @@ func TestValidateGeneratedApplications(t *testing.T) { }, }, }, - expectedErrors: []string{}, validationErrors: map[int]error{}, }, { @@ -1971,7 +1969,6 @@ func TestValidateGeneratedApplications(t *testing.T) { }, }, }, - expectedErrors: []string{"application destination can't have both name and server defined"}, validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: application destination can't have both name and server defined: my-cluster my-server")}, }, { @@ -1994,7 +1991,6 @@ func TestValidateGeneratedApplications(t *testing.T) { }, }, }, - expectedErrors: []string{"application references project DOES-NOT-EXIST which does not exist"}, validationErrors: map[int]error{0: fmt.Errorf("application references project DOES-NOT-EXIST which does not exist")}, }, { @@ -2017,7 +2013,6 @@ func TestValidateGeneratedApplications(t *testing.T) { }, }, }, - expectedErrors: []string{}, validationErrors: map[int]error{}, }, { @@ -2040,11 +2035,12 @@ func TestValidateGeneratedApplications(t *testing.T) { }, }, }, - expectedErrors: []string{"there are no clusters with this name: nonexistent-cluster"}, validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: unable to find destination server: there are no clusters with this name: nonexistent-cluster")}, }, } { t.Run(cc.name, func(t *testing.T) { + t.Parallel() + secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: "my-secret", @@ -2077,36 +2073,8 @@ func TestValidateGeneratedApplications(t *testing.T) { } appSetInfo := v1alpha1.ApplicationSet{} - validationErrors, _ := r.validateGeneratedApplications(context.TODO(), cc.apps, appSetInfo) - var errorMessages []string - for _, v := range validationErrors { - errorMessages = append(errorMessages, v.Error()) - } - - if len(errorMessages) == 0 { - assert.Empty(t, cc.expectedErrors, "Expected errors but none were seen") - } else { - // An error was returned: it should be expected - matched := false - for _, expectedErr := range cc.expectedErrors { - foundMatch := strings.Contains(strings.Join(errorMessages, ";"), expectedErr) - assert.True(t, foundMatch, "Unble to locate expected error: %s", cc.expectedErrors) - matched = matched || foundMatch - } - assert.True(t, matched, "An unexpected error occurrred: %v", err) - // validation message was returned: it should be expected - matched = false - foundMatch := reflect.DeepEqual(validationErrors, cc.validationErrors) - var message string - for _, v := range validationErrors { - message = v.Error() - break - } - assert.True(t, foundMatch, "Unble to locate validation message: %s", message) - matched = matched || foundMatch - assert.True(t, matched, "An unexpected error occurrred: %v", err) - } + assert.Equal(t, cc.validationErrors, validationErrors) }) } }