Skip to content

Commit

Permalink
test waitforsync
Browse files Browse the repository at this point in the history
Signed-off-by: varshaprasad96 <varshaprasad96@gmail.com>
  • Loading branch information
varshaprasad96 committed Feb 5, 2021
1 parent 52d5ec7 commit 09bce2f
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/cache/informertest"
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics"
"sigs.k8s.io/controller-runtime/pkg/internal/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
"sigs.k8s.io/controller-runtime/pkg/source"
)

Expand Down Expand Up @@ -169,6 +171,75 @@ var _ = Describe("controller", func() {
close(done)
}, 10.0)

It("should not error when channel is passed as a source", func(done Done) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

ins := &source.Channel{Source: make(chan event.GenericEvent)}
Expect(inject.StopChannelInto(make(<-chan struct{}), ins)).To(BeTrue())

ctrl.startWatches = []watchDescription{{
src: ins,
}}

go func() {
defer GinkgoRecover()
Expect(ctrl.Start(ctx)).To(Succeed())
}()

close(done)
})

It("should error when channel is passed as a source but stop channel is not injected", func(done Done) {
ch := make(chan event.GenericEvent)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

ins := &source.Channel{Source: ch}
ctrl.startWatches = []watchDescription{{
src: ins,
}}

errChan := make(chan error)

go func() {
defer GinkgoRecover()
err := ctrl.Start(ctx)
errChan <- err
}()

e := <-errChan
Expect(e).NotTo(BeNil())
Expect(e.Error()).To(ContainSubstring("must call InjectStop on Channel before calling Start"))
close(done)
})

It("should error when channel source is not specified", func(done Done) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ins := &source.Channel{}
Expect(inject.StopChannelInto(make(<-chan struct{}), ins)).To(BeTrue())

ctrl.startWatches = []watchDescription{{
src: &source.Channel{},
}}

errChan := make(chan error)

go func() {
defer GinkgoRecover()
err := ctrl.Start(ctx)
errChan <- err
}()

e := <-errChan
Expect(e).NotTo(BeNil())
Expect(e.Error()).To(ContainSubstring("must specify Channel.Source"))

close(done)
})

It("should call Start on sources with the appropriate EventHandler, Queue, and Predicates", func() {
pr1 := &predicate.Funcs{}
pr2 := &predicate.Funcs{}
Expand Down

0 comments on commit 09bce2f

Please sign in to comment.