github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/cluster_role_test.go (about)

     1  // +build kubeall kubernetes
     2  
     3  // NOTE: we have build tags to differentiate kubernetes tests from non-kubernetes tests. This is done because minikube
     4  // is heavy and can interfere with docker related tests in terratest. Specifically, many of the tests start to fail with
     5  // `connection refused` errors from `minikube`. To avoid overloading the system, we run the kubernetes tests and helm
     6  // tests separately from the others. This may not be necessary if you have a sufficiently powerful machine.  We
     7  // recommend at least 4 cores and 16GB of RAM if you want to run all the tests together.
     8  
     9  package k8s
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestGetClusterRoleEReturnsErrorForNonExistantClusterRole(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	options := NewKubectlOptions("", "", "default")
    21  	_, err := GetClusterRoleE(t, options, "non-existing-role")
    22  	require.Error(t, err)
    23  }
    24  
    25  func TestGetClusterRoleEReturnsCorrectClusterRoleInCorrectNamespace(t *testing.T) {
    26  	t.Parallel()
    27  
    28  	options := NewKubectlOptions("", "", "default")
    29  	defer KubectlDeleteFromString(t, options, EXAMPLE_CLUSTER_ROLE_YAML_TEMPLATE)
    30  	KubectlApplyFromString(t, options, EXAMPLE_CLUSTER_ROLE_YAML_TEMPLATE)
    31  
    32  	role := GetClusterRole(t, options, "terratest-cluster-role")
    33  	require.Equal(t, role.Name, "terratest-cluster-role")
    34  }
    35  
    36  const EXAMPLE_CLUSTER_ROLE_YAML_TEMPLATE = `---
    37  apiVersion: rbac.authorization.k8s.io/v1
    38  kind: ClusterRole
    39  metadata:
    40    name: 'terratest-cluster-role'
    41  rules:
    42  - apiGroups:
    43    - '*'
    44    resources:
    45    - '*'
    46    verbs:
    47    - '*'
    48  `