Skip to content

Commit

Permalink
Update dynamic controller tests with proper handler function
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hilaly committed Sep 26, 2024
1 parent bc9a427 commit 343a43e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/dynamiccontroller/dynamic_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic/fake"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

Expand Down Expand Up @@ -86,15 +87,19 @@ func TestRegisterAndUnregisterGVK(t *testing.T) {
// Give the controller time to start
time.Sleep(1 * time.Second)

handlerFunc := Handler(func(ctx context.Context, req controllerruntime.Request) error {
return nil
})

// Register GVK
err := dc.StartServingGVK(context.Background(), gvr, nil)
err := dc.StartServingGVK(context.Background(), gvr, handlerFunc)
require.NoError(t, err)

_, exists := dc.informers.Load(gvr)
assert.True(t, exists)

// Try to register again (should fail)
err = dc.StartServingGVK(context.Background(), gvr, nil)
err = dc.StartServingGVK(context.Background(), gvr, handlerFunc)
assert.Error(t, err)

// Unregister GVK
Expand Down

0 comments on commit 343a43e

Please sign in to comment.