github.com/terraform-modules-krish/terratest@v0.29.0/modules/k8s/kubectl_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/terraform-modules-krish/terratest/modules/random"
    17  	"github.com/stretchr/testify/require"
    18  )
    19  
    20  // Test that RunKubectlAndGetOutputE will run kubectl and return the output by running a can-i command call.
    21  func TestRunKubectlAndGetOutputReturnsOutput(t *testing.T) {
    22  	namespaceName := fmt.Sprintf("kubectl-test-%s", strings.ToLower(random.UniqueId()))
    23  	options := NewKubectlOptions("", "", namespaceName)
    24  	output, err := RunKubectlAndGetOutputE(t, options, "auth", "can-i", "get", "pods")
    25  	require.NoError(t, err)
    26  	require.Equal(t, output, "yes")
    27  }