Skip to content

Commit

Permalink
🌱 Remove async ginkgo tests
Browse files Browse the repository at this point in the history
Ginkgo has deprecated async tests with channels, and given that we're
not really using those properly or consistently, remove them from
controller runtime and simplify our tests.

Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information
vincepri committed Jun 22, 2021
1 parent 44a4c03 commit 8736073
Show file tree
Hide file tree
Showing 39 changed files with 262 additions and 691 deletions.
4 changes: 1 addition & 3 deletions pkg/builder/builder_suite_test.go
Expand Up @@ -45,7 +45,7 @@ func TestBuilder(t *testing.T) {
var testenv *envtest.Environment
var cfg *rest.Config

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

testenv = &envtest.Environment{}
Expand All @@ -63,8 +63,6 @@ var _ = BeforeSuite(func(done Done) {

webhook.DefaultPort, _, err = addr.Suggest("")
Expect(err).NotTo(HaveOccurred())

close(done)
}, 60)

var _ = AfterSuite(func() {
Expand Down
10 changes: 3 additions & 7 deletions pkg/builder/controller_test.go
Expand Up @@ -297,7 +297,7 @@ var _ = Describe("application", func() {
})

Describe("Start with ControllerManagedBy", func() {
It("should Reconcile Owns objects", func(done Done) {
It("should Reconcile Owns objects", func() {
m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

Expand All @@ -308,10 +308,9 @@ var _ = Describe("application", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
doReconcileTest(ctx, "3", bldr, m, false)
close(done)
}, 10)

It("should Reconcile Watches objects", func(done Done) {
It("should Reconcile Watches objects", func() {
m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

Expand All @@ -324,12 +323,11 @@ var _ = Describe("application", func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
doReconcileTest(ctx, "4", bldr, m, true)
close(done)
}, 10)
})

Describe("Set custom predicates", func() {
It("should execute registered predicates only for assigned kind", func(done Done) {
It("should execute registered predicates only for assigned kind", func() {
m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -385,8 +383,6 @@ var _ = Describe("application", func() {
Expect(deployPrctExecuted).To(BeTrue(), "Deploy predicated should be called at least once")
Expect(replicaSetPrctExecuted).To(BeTrue(), "ReplicaSet predicated should be called at least once")
Expect(allPrctExecuted).To(BeNumerically(">=", 2), "Global Predicated should be called at least twice")

close(done)
})
})

Expand Down
4 changes: 1 addition & 3 deletions pkg/cache/cache_suite_test.go
Expand Up @@ -39,7 +39,7 @@ var testenv *envtest.Environment
var cfg *rest.Config
var clientset *kubernetes.Clientset

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

testenv = &envtest.Environment{}
Expand All @@ -50,8 +50,6 @@ var _ = BeforeSuite(func(done Done) {

clientset, err = kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())

close(done)
}, 60)

var _ = AfterSuite(func() {
Expand Down
12 changes: 4 additions & 8 deletions pkg/cache/cache_test.go
Expand Up @@ -886,7 +886,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
})
Describe("as an Informer", func() {
Context("with structured objects", func() {
It("should be able to get informer for the object", func(done Done) {
It("should be able to get informer for the object", func() {
By("getting a shared index informer for a pod")
pod := &kcorev1.Pod{
ObjectMeta: kmetav1.ObjectMeta{
Expand Down Expand Up @@ -922,9 +922,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object is received on the channel")
Eventually(out).Should(Receive(Equal(pod)))
close(done)
})
It("should be able to get an informer by group/version/kind", func(done Done) {
It("should be able to get an informer by group/version/kind", func() {
By("getting an shared index informer for gvk = core/v1/pod")
gvk := schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}
sii, err := informerCache.GetInformerForKind(context.TODO(), gvk)
Expand Down Expand Up @@ -961,7 +960,6 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object is received on the channel")
Eventually(out).Should(Receive(Equal(pod)))
close(done)
})
It("should be able to index an object field then retrieve objects by that field", func() {
By("creating the cache")
Expand Down Expand Up @@ -1031,7 +1029,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
})
})
Context("with unstructured objects", func() {
It("should be able to get informer for the object", func(done Done) {
It("should be able to get informer for the object", func() {
By("getting a shared index informer for a pod")

pod := &unstructured.Unstructured{
Expand Down Expand Up @@ -1073,7 +1071,6 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object is received on the channel")
Eventually(out).Should(Receive(Equal(pod)))
close(done)
}, 3)

It("should be able to index an object field then retrieve objects by that field", func() {
Expand Down Expand Up @@ -1146,7 +1143,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
})
})
Context("with metadata-only objects", func() {
It("should be able to get informer for the object", func(done Done) {
It("should be able to get informer for the object", func() {
By("getting a shared index informer for a pod")

pod := &kcorev1.Pod{
Expand Down Expand Up @@ -1194,7 +1191,6 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca

By("verifying the object's metadata is received on the channel")
Eventually(out).Should(Receive(Equal(podMeta)))
close(done)
}, 3)

It("should be able to index an object field then retrieve objects by that field", func() {
Expand Down
7 changes: 2 additions & 5 deletions pkg/certwatcher/certwatcher_suite_test.go
Expand Up @@ -38,15 +38,12 @@ func TestSource(t *testing.T) {
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
}

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

close(done)
}, 60)

var _ = AfterSuite(func(done Done) {
var _ = AfterSuite(func() {
for _, file := range []string{certPath, keyPath} {
_ = os.Remove(file)
}
close(done)
}, 60)
4 changes: 1 addition & 3 deletions pkg/client/apiutil/apiutil_suite_test.go
Expand Up @@ -36,11 +36,9 @@ func TestSource(t *testing.T) {

var cfg *rest.Config

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

// for things that technically need a rest.Config for defaulting, but don't actually use them
cfg = &rest.Config{}

close(done)
}, 60)
1 change: 0 additions & 1 deletion pkg/client/apiutil/dynamicrestmapper_test.go
Expand Up @@ -133,7 +133,6 @@ var _ = Describe("Dynamic REST Mapper", func() {
go func() {
defer GinkgoRecover()
Expect(callWithOther()).To(Succeed())
close(done)
}()

Expect(callWithOther()).To(Succeed())
Expand Down
4 changes: 1 addition & 3 deletions pkg/client/client_suite_test.go
Expand Up @@ -40,7 +40,7 @@ var testenv *envtest.Environment
var cfg *rest.Config
var clientset *kubernetes.Clientset

var _ = BeforeSuite(func(done Done) {
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

testenv = &envtest.Environment{}
Expand All @@ -51,8 +51,6 @@ var _ = BeforeSuite(func(done Done) {

clientset, err = kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())

close(done)
}, 60)

var _ = AfterSuite(func() {
Expand Down

0 comments on commit 8736073

Please sign in to comment.