-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for config map watcher
Signed-off-by: chandankumar4 <[email protected]>
- Loading branch information
1 parent
c6681fe
commit a61cdfd
Showing
3 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/numaproj/numaplane/internal/controller/config" | ||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
func Test_watchConfigMaps(t *testing.T) { | ||
ctx := context.TODO() | ||
scheme := runtime.NewScheme() | ||
err := corev1.AddToScheme(scheme) | ||
assert.NoError(t, err) | ||
|
||
clientSet := fake.NewSimpleClientset() | ||
go watchConfigMaps(ctx, clientSet, "default") | ||
time.Sleep(20 * time.Second) | ||
|
||
data, err := os.ReadFile("../../../tests/config/controller-definitions-config.yaml") | ||
assert.NoError(t, err) | ||
// Create a new ConfigMap object | ||
configMap := &corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "numaflow-controller-definitions-config", | ||
Namespace: "default", | ||
Labels: map[string]string{ | ||
"config": "numaflow-controller-rollout", | ||
}, | ||
}, | ||
Data: map[string]string{ | ||
"controller_definitions.yaml": string(data), | ||
}, | ||
} | ||
|
||
// Create the ConfigMap object in the fake clientset | ||
_, err = clientSet.CoreV1().ConfigMaps("default").Create(ctx, configMap, metav1.CreateOptions{}) | ||
assert.NoError(t, err) | ||
|
||
// Wait for the controller to process the ConfigMap | ||
time.Sleep(10 * time.Second) | ||
|
||
// Validate the controller definition config is set correctly | ||
definition := config.GetConfigManagerInstance().GetControllerDefinitionsConfig() | ||
assert.Len(t, definition, 2) | ||
|
||
// Create the ConfigMap object in the fake clientset | ||
err = clientSet.CoreV1().ConfigMaps("default").Delete(ctx, configMap.Name, metav1.DeleteOptions{}) | ||
assert.NoError(t, err) | ||
|
||
// Wait for the controller to process the ConfigMap | ||
time.Sleep(10 * time.Second) | ||
|
||
definition = config.GetConfigManagerInstance().GetControllerDefinitionsConfig() | ||
assert.Len(t, definition, 0) | ||
} |