github.com/mponton/terratest@v0.44.0/modules/k8s/kubectl_test.go (about)

     1  //go:build kubeall || kubernetes
     2  // +build kubeall kubernetes
     3  
     4  // NOTE: we have build tags to differentiate kubernetes tests from non-kubernetes tests. This is done because minikube
     5  // is heavy and can interfere with docker related tests in terratest. Specifically, many of the tests start to fail with
     6  // `connection refused` errors from `minikube`. To avoid overloading the system, we run the kubernetes tests and helm
     7  // tests separately from the others. This may not be necessary if you have a sufficiently powerful machine.  We
     8  // recommend at least 4 cores and 16GB of RAM if you want to run all the tests together.
     9  
    10  package k8s
    11  
    12  import (
    13  	"fmt"
    14  	"strings"
    15  	"testing"
    16  
    17  	"github.com/mponton/terratest/modules/random"
    18  	"github.com/stretchr/testify/require"
    19  )
    20  
    21  // Test that RunKubectlAndGetOutputE will run kubectl and return the output by running a can-i command call.
    22  func TestRunKubectlAndGetOutputReturnsOutput(t *testing.T) {
    23  	namespaceName := fmt.Sprintf("kubectl-test-%s", strings.ToLower(random.UniqueId()))
    24  	options := NewKubectlOptions("", "", namespaceName)
    25  	output, err := RunKubectlAndGetOutputE(t, options, "auth", "can-i", "get", "pods")
    26  	require.NoError(t, err)
    27  	require.Equal(t, output, "yes")
    28  }