Skip to content

Commit

Permalink
Update to reduce duplicate code, remove unecessary test
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuto committed Feb 4, 2021
1 parent faae06a commit 57865e9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
10 changes: 2 additions & 8 deletions modules/k8s/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ func CreateNamespaceWithMetadataE(t testing.TestingT, options *KubectlOptions, n

// CreateNamespaceWithMetadata will create a new Kubernetes namespace on the cluster targeted by the provided options and
// with the provided metadata. This method expects the entire namespace ObjectMeta to be passed in, so you'll need to set the name within the ObjectMeta struct yourself.
// This will fail the test if there is an error while creating the namespace.
func CreateNamespaceWithMetadata(t testing.TestingT, options *KubectlOptions, namespaceObjectMeta metav1.ObjectMeta) {
clientset, err := GetKubernetesClientFromOptionsE(t, options)
require.NoError(t, err)

namespace := corev1.Namespace{
ObjectMeta: namespaceObjectMeta,
}
_, err = clientset.CoreV1().Namespaces().Create(context.Background(), &namespace, metav1.CreateOptions{})
require.NoError(t, err)
require.NoError(t, CreateNamespaceWithMetadataE(t, options, namespaceObjectMeta))
}

// GetNamespace will query the Kubernetes cluster targeted by the provided options for the requested namespace. This will
Expand Down
24 changes: 0 additions & 24 deletions modules/k8s/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ func TestNamespaces(t *testing.T) {
require.Equal(t, namespace.Name, namespaceName)
}

func TestNamespaceWithMetadataE(t *testing.T) {
t.Parallel()

uniqueId := random.UniqueId()
namespaceName := strings.ToLower(uniqueId)
options := NewKubectlOptions("", "", namespaceName)
namespaceLabels := map[string]string{"foo": "bar"}
namespaceObjectMetaWithLabels := metav1.ObjectMeta{
Name: namespaceName,
Labels: namespaceLabels,
}
err := CreateNamespaceWithMetadataE(t, options, namespaceObjectMetaWithLabels)
require.NoError(t, err)
defer func() {
DeleteNamespace(t, options, namespaceName)
namespace := GetNamespace(t, options, namespaceName)
require.Equal(t, namespace.Status.Phase, corev1.NamespaceTerminating)
}()

namespace := GetNamespace(t, options, namespaceName)
require.Equal(t, namespace.Name, namespaceName)
require.Equal(t, namespace.Labels, namespaceLabels)
}

func TestNamespaceWithMetadata(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 57865e9

Please sign in to comment.