Skip to content

Commit 2e0d553

Browse files
committed
add tests for excludeNamespace and exclusiveNamespace scenarios/
1 parent 16b4c33 commit 2e0d553

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

internal/controller/controller_integration_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ func (m *mockRecordPoster) getRecords() []*deploymentrecord.DeploymentRecord {
4141
return slices.Clone(m.records)
4242
}
4343

44-
func setup(t *testing.T, namespace string, onlyNamepsace string, excludeNamespaces string) (*kubernetes.Clientset, *mockRecordPoster) {
44+
const testControllerNamespace = "test-controller-ns"
45+
46+
func setup(t *testing.T, onlyNamepsace string, excludeNamespaces string) (*kubernetes.Clientset, *mockRecordPoster) {
4547
t.Helper()
4648
testEnv := &envtest.Environment{}
4749

@@ -61,7 +63,7 @@ func setup(t *testing.T, namespace string, onlyNamepsace string, excludeNamespac
6163
_ = testEnv.Stop()
6264
})
6365

64-
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
66+
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testControllerNamespace}}
6567
_, err = clientset.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
6668
if err != nil {
6769
t.Fatalf("failed to create namespace: %v", err)
@@ -274,7 +276,7 @@ func TestControllerIntegration_KubernetesDeployment(t *testing.T) {
274276
}
275277
t.Parallel()
276278
namespace := "test-controller-ns"
277-
clientset, mock := setup(t, namespace, "", "")
279+
clientset, mock := setup(t, "", "")
278280

279281
// Create deployment, replicaset, and pod; expect 1 record
280282
deployment := makeDeployment(t, clientset, []metav1.OwnerReference{}, namespace, "test-deployment")
@@ -335,7 +337,7 @@ func TestControllerIntegration_InitContainers(t *testing.T) {
335337
}
336338
t.Parallel()
337339
namespace := "test-controller-ns"
338-
clientset, mock := setup(t, namespace, "", "")
340+
clientset, mock := setup(t, "", "")
339341

340342
// Create deployment, replicaset, and pod with an init container; expect 2 records (one per container)
341343
deployment := makeDeployment(t, clientset, []metav1.OwnerReference{}, namespace, "init-deployment")
@@ -394,7 +396,7 @@ func TestControllerIntegration_OnlyWatchOneNamespace(t *testing.T) {
394396
t.Parallel()
395397
namespace1 := "namespace1"
396398
namespace2 := "namespace2"
397-
clientset, mock := setup(t, "test-controller-ns", namespace1, "")
399+
clientset, mock := setup(t, namespace1, "")
398400

399401
ns1 := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace1}}
400402
_, err := clientset.CoreV1().Namespaces().Create(context.Background(), ns1, metav1.CreateOptions{})
@@ -452,7 +454,7 @@ func TestControllerIntegration_ExcludeNamespaces(t *testing.T) {
452454
namespace1 := "namespace1"
453455
namespace2 := "namespace2"
454456
namespace3 := "namespace3"
455-
clientset, mock := setup(t, "test-controller-ns", "", fmt.Sprintf("%s,%s", namespace2, namespace3))
457+
clientset, mock := setup(t, "", fmt.Sprintf("%s,%s", namespace2, namespace3))
456458

457459
ns1 := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace1}}
458460
_, err := clientset.CoreV1().Namespaces().Create(context.Background(), ns1, metav1.CreateOptions{})

0 commit comments

Comments
 (0)