github.com/argoproj/argo-cd/v3@v3.2.1/controller/sort_delete_test.go (about) 1 package controller 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/argoproj/gitops-engine/pkg/sync/common" 10 . "github.com/argoproj/gitops-engine/pkg/utils/testing" 11 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 12 ) 13 14 func TestFilterObjectsForDeletion(t *testing.T) { 15 tests := []struct { 16 input []string 17 want []string 18 }{ 19 {[]string{"1", "5", "7", "7", "4"}, []string{"7", "7"}}, 20 {[]string{"1", "5", "2", "2", "4"}, []string{"5"}}, 21 {[]string{"1"}, []string{"1"}}, 22 {[]string{}, []string{}}, 23 } 24 for _, tt := range tests { 25 in := sliceOfObjectsWithSyncWaves(tt.input) 26 need := sliceOfObjectsWithSyncWaves(tt.want) 27 got := FilterObjectsForDeletion(in) 28 assert.True(t, reflect.DeepEqual(got, need), "Received unexpected objects for deletion") 29 } 30 } 31 32 func podWithSyncWave(wave string) *unstructured.Unstructured { 33 return Annotate(NewPod(), common.AnnotationSyncWave, wave) 34 } 35 36 func sliceOfObjectsWithSyncWaves(waves []string) []*unstructured.Unstructured { 37 objects := make([]*unstructured.Unstructured, 0) 38 for _, wave := range waves { 39 objects = append(objects, podWithSyncWave(wave)) 40 } 41 return objects 42 }