github.com/argoproj/argo-cd@v1.8.7/controller/sort_delete_test.go (about)

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