-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
- Loading branch information
Frank Jogeleit
committed
Apr 25, 2024
1 parent
38c665a
commit 0f2f1c9
Showing
2 changed files
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package leaderelection_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kyverno/policy-reporter/pkg/leaderelection" | ||
"k8s.io/client-go/kubernetes/typed/coordination/v1/fake" | ||
) | ||
|
||
func TestClient(t *testing.T) { | ||
client := leaderelection.New(&fake.FakeCoordinationV1{}, "policy-reporter", "namespace", "pod-123", time.Second, time.Second, time.Second, false) | ||
|
||
if client == nil { | ||
t.Fatal("failed to create leaderelection client") | ||
} | ||
|
||
client.RegisterOnNew(func(currentID, lockID string) {}) | ||
client.RegisterOnStart(func(c context.Context) {}) | ||
client.RegisterOnStop(func() {}) | ||
|
||
lock := client.CreateLock() | ||
|
||
if lock.LeaseMeta.Name != "policy-reporter" { | ||
t.Error("unexpected lease name") | ||
} | ||
if lock.LeaseMeta.Namespace != "namespace" { | ||
t.Error("unexpected lease namespace") | ||
} | ||
if lock.LockConfig.Identity != "pod-123" { | ||
t.Error("unexpected lease identity") | ||
} | ||
} |
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