github.com/argoproj/argo-cd/v3@v3.2.1/cmd/util/project_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  
     9  	"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
    10  )
    11  
    12  func TestProjectOpts_ResourceLists(t *testing.T) {
    13  	opts := ProjectOpts{
    14  		allowedNamespacedResources: []string{"ConfigMap"},
    15  		deniedNamespacedResources:  []string{"apps/DaemonSet"},
    16  		allowedClusterResources:    []string{"apiextensions.k8s.io/CustomResourceDefinition"},
    17  		deniedClusterResources:     []string{"rbac.authorization.k8s.io/ClusterRole"},
    18  	}
    19  
    20  	assert.ElementsMatch(t, []metav1.GroupKind{{Kind: "ConfigMap"}}, opts.GetAllowedNamespacedResources())
    21  	assert.ElementsMatch(t, []metav1.GroupKind{{Group: "apps", Kind: "DaemonSet"}}, opts.GetDeniedNamespacedResources())
    22  	assert.ElementsMatch(t, []metav1.GroupKind{{Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition"}}, opts.GetAllowedClusterResources())
    23  	assert.ElementsMatch(t, []metav1.GroupKind{{Group: "rbac.authorization.k8s.io", Kind: "ClusterRole"}}, opts.GetDeniedClusterResources())
    24  }
    25  
    26  func TestProjectOpts_GetDestinationServiceAccounts(t *testing.T) {
    27  	opts := ProjectOpts{
    28  		destinationServiceAccounts: []string{
    29  			"https://192.168.99.100:8443,test-ns,test-sa",
    30  			"https://kubernetes.default.svc.local:6443,guestbook,guestbook-sa",
    31  		},
    32  	}
    33  
    34  	assert.ElementsMatch(t,
    35  		[]v1alpha1.ApplicationDestinationServiceAccount{
    36  			{
    37  				Server:                "https://192.168.99.100:8443",
    38  				Namespace:             "test-ns",
    39  				DefaultServiceAccount: "test-sa",
    40  			},
    41  			{
    42  				Server:                "https://kubernetes.default.svc.local:6443",
    43  				Namespace:             "guestbook",
    44  				DefaultServiceAccount: "guestbook-sa",
    45  			},
    46  		}, opts.GetDestinationServiceAccounts(),
    47  	)
    48  }