Skip to content

Commit

Permalink
full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Mendoza committed Apr 24, 2024
1 parent 3b5efbc commit e3908ab
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions mock/mocktest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/linode/cluster-api-provider-linode/mock"

Expand Down Expand Up @@ -97,20 +99,35 @@ func waitCh(counter *sync.WaitGroup) <-chan struct{} {
var _ = Describe("controller suite", Label("suite"), func() {
suite := NewControllerSuite(GinkgoT(), mock.MockK8sClient{})

suite.Run(Paths(
Call("call", func(ctx context.Context, mck Mock) {
mck.K8sClient.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).Return(nil)
}),
Result("result", func(ctx context.Context, mck Mock) {
mck.recorder.Event(nil, "", "", "event")
err := mck.K8sClient.Get(ctx, client.ObjectKey{Namespace: "default", Name: "myobj"}, nil)
Expect(err).NotTo(HaveOccurred())
}),
))
})

var _ = Describe("controller suite with events/logs", Label("suite"), func() {
suite := NewControllerSuite(GinkgoT(), mock.MockK8sClient{})

suite.Run(Paths(
Either(
Call("call1", func(_ context.Context, mck Mock) {
mck.recorder.Event(nil, "", "", "+")
mck.logger.Info("+")
mck.Recorder().Event(nil, "", "", "+")
mck.Logger().Info("+")
}),
Call("call2", func(_ context.Context, mck Mock) {
mck.recorder.Event(nil, "", "", "+")
mck.logger.Info("+")
mck.Recorder().Event(nil, "", "", "+")
mck.Logger().Info("+")
}),
),
Result("result", func(_ context.Context, mck Mock) {
mck.recorder.Event(nil, "", "", "+")
mck.logger.Info("+")
mck.Recorder().Event(nil, "", "", "+")
mck.Logger().Info("+")

Expect(strings.Count(mck.Events(), "+")).To(Equal(2))
Expect(strings.Count(mck.Logs(), "+")).To(Equal(2))
Expand Down

0 comments on commit e3908ab

Please sign in to comment.