forked from codefresh-io/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_delete_test.go
41 lines (36 loc) · 1.12 KB
/
sort_delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package controller
import (
"reflect"
"testing"
"github.com/argoproj/gitops-engine/pkg/sync/common"
. "github.com/argoproj/gitops-engine/pkg/utils/testing"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func TestFilterObjectsForDeletion(t *testing.T) {
tests := []struct {
input []string
want []string
}{
{[]string{"1", "5", "7", "7", "4"}, []string{"7", "7"}},
{[]string{"1", "5", "2", "2", "4"}, []string{"5"}},
{[]string{"1"}, []string{"1"}},
{[]string{}, []string{}},
}
for _, tt := range tests {
in := sliceOfObjectsWithSyncWaves(tt.input)
need := sliceOfObjectsWithSyncWaves(tt.want)
if got := FilterObjectsForDeletion(in); !reflect.DeepEqual(got, need) {
t.Errorf("Received unexpected objects for deletion = %v, want %v", got, need)
}
}
}
func podWithSyncWave(wave string) *unstructured.Unstructured {
return Annotate(NewPod(), common.AnnotationSyncWave, wave)
}
func sliceOfObjectsWithSyncWaves(waves []string) []*unstructured.Unstructured {
objects := make([]*unstructured.Unstructured, 0)
for _, wave := range waves {
objects = append(objects, podWithSyncWave(wave))
}
return objects
}