Skip to content

Commit

Permalink
Test for event creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Sep 10, 2021
1 parent d464ae3 commit 9a16cb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions controllers/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ var _ = Describe("The controller", func() {
})

It("should use the profile described in the annotation", func() {
drainEvents := func() int {
count := 0
loop:
for {
select {
case <-eventRecorder.Events:
count++
break
default:
break loop
}
}
return count
}
drainEvents()

var node corev1.Node
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: "targetnode"}, &node)
Expect(err).To(Succeed())
Expand All @@ -102,6 +118,7 @@ var _ = Describe("The controller", func() {
err = k8sClient.Get(context.Background(), client.ObjectKey{Name: "targetnode"}, &node)
Expect(err).To(Succeed())
Expect(node.Labels["alter"]).To(Equal(trueStr))
Expect(drainEvents()).To(BeNumerically(">", 2))
})

It("should annotate the last used profile", func() {
Expand Down
4 changes: 3 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var cfg *rest.Config
var k8sClient client.Client
var k8sManager ctrl.Manager
var testEnv *envtest.Environment
var eventRecorder *record.FakeRecorder

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
Expand Down Expand Up @@ -130,11 +131,12 @@ var _ = BeforeSuite(func() {
})
Expect(err).ToNot(HaveOccurred())

eventRecorder = record.NewFakeRecorder(1024)
err = (&NodeReconciler{
Client: k8sManager.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("maintenance"),
Scheme: k8sManager.GetScheme(),
Recorder: record.NewFakeRecorder(1024),
Recorder: eventRecorder,
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

Expand Down

0 comments on commit 9a16cb5

Please sign in to comment.