github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/secret_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  	"fmt"
    13  	"strings"
    14  	"testing"
    15  
    16  	"github.com/stretchr/testify/require"
    17  
    18  	"github.com/terraform-modules-krish/terratest/modules/random"
    19  )
    20  
    21  func TestGetSecretEReturnsErrorForNonExistantSecret(t *testing.T) {
    22  	t.Parallel()
    23  
    24  	options := NewKubectlOptions("", "", "default")
    25  	_, err := GetSecretE(t, options, "master-password")
    26  	require.Error(t, err)
    27  }
    28  
    29  func TestGetSecretEReturnsCorrectSecretInCorrectNamespace(t *testing.T) {
    30  	t.Parallel()
    31  
    32  	uniqueID := strings.ToLower(random.UniqueId())
    33  	options := NewKubectlOptions("", "", uniqueID)
    34  	configData := fmt.Sprintf(EXAMPLE_SECRET_YAML_TEMPLATE, uniqueID, uniqueID)
    35  	defer KubectlDeleteFromString(t, options, configData)
    36  	KubectlApplyFromString(t, options, configData)
    37  
    38  	secret := GetSecret(t, options, "master-password")
    39  	require.Equal(t, secret.Name, "master-password")
    40  	require.Equal(t, secret.Namespace, uniqueID)
    41  }
    42  
    43  const EXAMPLE_SECRET_YAML_TEMPLATE = `---
    44  apiVersion: v1
    45  kind: Namespace
    46  metadata:
    47    name: %s
    48  ---
    49  apiVersion: v1
    50  kind: Secret
    51  metadata:
    52    name: master-password
    53    namespace: %s
    54  `