github.com/argoproj-labs/argocd-operator@v0.10.0/controllers/argocd/service_test.go (about)

     1  package argocd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/argoproj-labs/argocd-operator/common"
     9  )
    10  
    11  func TestEnsureAutoTLSAnnotation(t *testing.T) {
    12  	a := makeTestArgoCD()
    13  	t.Run("Ensure annotation will be set for OpenShift", func(t *testing.T) {
    14  		routeAPIFound = true
    15  		svc := newService(a)
    16  
    17  		// Annotation is inserted, update is required
    18  		needUpdate := ensureAutoTLSAnnotation(svc, "some-secret", true)
    19  		assert.Equal(t, needUpdate, true)
    20  		atls, ok := svc.Annotations[common.AnnotationOpenShiftServiceCA]
    21  		assert.Equal(t, ok, true)
    22  		assert.Equal(t, atls, "some-secret")
    23  
    24  		// Annotation already set, doesn't need update
    25  		needUpdate = ensureAutoTLSAnnotation(svc, "some-secret", true)
    26  		assert.Equal(t, needUpdate, false)
    27  	})
    28  	t.Run("Ensure annotation will be unset for OpenShift", func(t *testing.T) {
    29  		routeAPIFound = true
    30  		svc := newService(a)
    31  		svc.Annotations = make(map[string]string)
    32  		svc.Annotations[common.AnnotationOpenShiftServiceCA] = "some-secret"
    33  
    34  		// Annotation getting removed, update required
    35  		needUpdate := ensureAutoTLSAnnotation(svc, "some-secret", false)
    36  		assert.Equal(t, needUpdate, true)
    37  		_, ok := svc.Annotations[common.AnnotationOpenShiftServiceCA]
    38  		assert.Equal(t, ok, false)
    39  
    40  		// Annotation does not exist, no update required
    41  		needUpdate = ensureAutoTLSAnnotation(svc, "some-secret", false)
    42  		assert.Equal(t, needUpdate, false)
    43  	})
    44  	t.Run("Ensure annotation will not be set for non-OpenShift", func(t *testing.T) {
    45  		routeAPIFound = false
    46  		svc := newService(a)
    47  		needUpdate := ensureAutoTLSAnnotation(svc, "some-secret", true)
    48  		assert.Equal(t, needUpdate, false)
    49  		_, ok := svc.Annotations[common.AnnotationOpenShiftServiceCA]
    50  		assert.Equal(t, ok, false)
    51  	})
    52  }