github.com/argoproj/argo-cd@v1.8.7/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  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     8  
     9  	"github.com/argoproj/argo-cd/test"
    10  )
    11  
    12  func TestGetRevision(t *testing.T) {
    13  	type args struct {
    14  		obj *unstructured.Unstructured
    15  	}
    16  	tests := []struct {
    17  		name string
    18  		args args
    19  		want int64
    20  	}{
    21  		{"Nil", args{}, 0},
    22  		{"Empty", args{obj: NewPod()}, 0},
    23  		{"Invalid", args{obj: revisionExample("deployment.kubernetes.io/revision", "garbage")}, 0},
    24  		{"Garbage", args{obj: revisionExample("garbage.kubernetes.io/revision", "1")}, 0},
    25  		{"Deployments", args{obj: revisionExample("deployment.kubernetes.io/revision", "1")}, 1},
    26  		{"Rollouts", args{obj: revisionExample("rollout.argoproj.io/revision", "1")}, 1},
    27  		{"ControllerRevision", args{obj: test.NewControllerRevision()}, 2},
    28  	}
    29  	for _, tt := range tests {
    30  		t.Run(tt.name, func(t *testing.T) {
    31  			if got := GetRevision(tt.args.obj); got != tt.want {
    32  				t.Errorf("GetRevision() = %v, want %v", got, tt.want)
    33  			}
    34  		})
    35  	}
    36  }
    37  
    38  func revisionExample(name, value string) *unstructured.Unstructured {
    39  	pod := NewPod()
    40  	pod.SetAnnotations(map[string]string{name: value})
    41  	return pod
    42  }