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

     1  //go:build kubernetes
     2  // +build 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  	"testing"
    14  
    15  	"github.com/stretchr/testify/require"
    16  
    17  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    18  	_ "k8s.io/client-go/plugin/pkg/client/auth"
    19  )
    20  
    21  func TestListEventsEReturnsNilErrorWhenListingEvents(t *testing.T) {
    22  	t.Parallel()
    23  
    24  	options := NewKubectlOptions("", "", "kube-system")
    25  	events, err := ListEventsE(t, options, v1.ListOptions{})
    26  	require.Nil(t, err)
    27  	require.Greater(t, len(events), 0)
    28  }
    29  
    30  func TestListEventsInNamespace(t *testing.T) {
    31  	t.Parallel()
    32  
    33  	options := NewKubectlOptions("", "", "kube-system")
    34  	events := ListEvents(t, options, v1.ListOptions{})
    35  	require.Greater(t, len(events), 0)
    36  }
    37  
    38  func TestListEventsReturnsZeroEventsIfNoneCreated(t *testing.T) {
    39  	t.Parallel()
    40  	ns := "test-ns"
    41  
    42  	options := NewKubectlOptions("", "", "")
    43  
    44  	defer DeleteNamespace(t, options, ns)
    45  	CreateNamespace(t, options, ns)
    46  
    47  	options.Namespace = ns
    48  	events := ListEvents(t, options, v1.ListOptions{})
    49  	require.Equal(t, 0, len(events))
    50  }