github.com/argoproj/argo-cd/v3@v3.2.1/util/resource/revision_test.go (about) 1 package resource 2 3 import ( 4 "testing" 5 6 . "github.com/argoproj/gitops-engine/pkg/utils/testing" 7 "github.com/stretchr/testify/assert" 8 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 9 10 "github.com/argoproj/argo-cd/v3/test" 11 ) 12 13 func TestGetRevision(t *testing.T) { 14 type args struct { 15 obj *unstructured.Unstructured 16 } 17 tests := []struct { 18 name string 19 args args 20 want int64 21 }{ 22 {"Nil", args{}, 0}, 23 {"Empty", args{obj: NewPod()}, 0}, 24 {"Invalid", args{obj: revisionExample("deployment.kubernetes.io/revision", "garbage")}, 0}, 25 {"Garbage", args{obj: revisionExample("garbage.kubernetes.io/revision", "1")}, 0}, 26 {"Deployments", args{obj: revisionExample("deployment.kubernetes.io/revision", "1")}, 1}, 27 {"Rollouts", args{obj: revisionExample("rollout.argoproj.io/revision", "1")}, 1}, 28 {"ControllerRevision", args{obj: test.NewControllerRevision()}, 2}, 29 } 30 for _, tt := range tests { 31 t.Run(tt.name, func(t *testing.T) { 32 assert.Equal(t, tt.want, GetRevision(tt.args.obj), "GetRevision()") 33 }) 34 } 35 } 36 37 func revisionExample(name, value string) *unstructured.Unstructured { 38 pod := NewPod() 39 pod.SetAnnotations(map[string]string{name: value}) 40 return pod 41 }