Skip to content

Commit 1f32e46

Browse files
committed
🌱 Remove async ginkgo tests
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 <[email protected]>
1 parent b826f39 commit 1f32e46

38 files changed

+262
-690
lines changed

pkg/builder/builder_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestBuilder(t *testing.T) {
4545
var testenv *envtest.Environment
4646
var cfg *rest.Config
4747

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

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

6464
webhook.DefaultPort, _, err = addr.Suggest("")
6565
Expect(err).NotTo(HaveOccurred())
66-
67-
close(done)
6866
}, 60)
6967

7068
var _ = AfterSuite(func() {

pkg/builder/controller_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ var _ = Describe("application", func() {
297297
})
298298

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

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

314-
It("should Reconcile Watches objects", func(done Done) {
313+
It("should Reconcile Watches objects", func() {
315314
m, err := manager.New(cfg, manager.Options{})
316315
Expect(err).NotTo(HaveOccurred())
317316

@@ -324,12 +323,11 @@ var _ = Describe("application", func() {
324323
ctx, cancel := context.WithCancel(context.Background())
325324
defer cancel()
326325
doReconcileTest(ctx, "4", bldr, m, true)
327-
close(done)
328326
}, 10)
329327
})
330328

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

@@ -385,8 +383,6 @@ var _ = Describe("application", func() {
385383
Expect(deployPrctExecuted).To(BeTrue(), "Deploy predicated should be called at least once")
386384
Expect(replicaSetPrctExecuted).To(BeTrue(), "ReplicaSet predicated should be called at least once")
387385
Expect(allPrctExecuted).To(BeNumerically(">=", 2), "Global Predicated should be called at least twice")
388-
389-
close(done)
390386
})
391387
})
392388

pkg/cache/cache_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var testenv *envtest.Environment
3939
var cfg *rest.Config
4040
var clientset *kubernetes.Clientset
4141

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

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

5151
clientset, err = kubernetes.NewForConfig(cfg)
5252
Expect(err).NotTo(HaveOccurred())
53-
54-
close(done)
5553
}, 60)
5654

5755
var _ = AfterSuite(func() {

pkg/cache/cache_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
885885
})
886886
Describe("as an Informer", func() {
887887
Context("with structured objects", func() {
888-
It("should be able to get informer for the object", func(done Done) {
888+
It("should be able to get informer for the object", func() {
889889
By("getting a shared index informer for a pod")
890890
pod := &corev1.Pod{
891891
ObjectMeta: metav1.ObjectMeta{
@@ -921,9 +921,8 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
921921

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

961960
By("verifying the object is received on the channel")
962961
Eventually(out).Should(Receive(Equal(pod)))
963-
close(done)
964962
})
965963
It("should be able to index an object field then retrieve objects by that field", func() {
966964
By("creating the cache")
@@ -1030,7 +1028,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
10301028
})
10311029
})
10321030
Context("with unstructured objects", func() {
1033-
It("should be able to get informer for the object", func(done Done) {
1031+
It("should be able to get informer for the object", func() {
10341032
By("getting a shared index informer for a pod")
10351033

10361034
pod := &unstructured.Unstructured{
@@ -1072,7 +1070,6 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
10721070

10731071
By("verifying the object is received on the channel")
10741072
Eventually(out).Should(Receive(Equal(pod)))
1075-
close(done)
10761073
}, 3)
10771074

10781075
It("should be able to index an object field then retrieve objects by that field", func() {
@@ -1145,7 +1142,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
11451142
})
11461143
})
11471144
Context("with metadata-only objects", func() {
1148-
It("should be able to get informer for the object", func(done Done) {
1145+
It("should be able to get informer for the object", func() {
11491146
By("getting a shared index informer for a pod")
11501147

11511148
pod := &corev1.Pod{
@@ -1193,7 +1190,6 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
11931190

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

11991195
It("should be able to index an object field then retrieve objects by that field", func() {

pkg/certwatcher/certwatcher_suite_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ func TestSource(t *testing.T) {
3838
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)})
3939
}
4040

41-
var _ = BeforeSuite(func(done Done) {
41+
var _ = BeforeSuite(func() {
4242
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
43-
44-
close(done)
4543
}, 60)
4644

47-
var _ = AfterSuite(func(done Done) {
45+
var _ = AfterSuite(func() {
4846
for _, file := range []string{certPath, keyPath} {
4947
_ = os.Remove(file)
5048
}
51-
close(done)
5249
}, 60)

pkg/client/apiutil/apiutil_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ func TestSource(t *testing.T) {
3636

3737
var cfg *rest.Config
3838

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

4242
// for things that technically need a rest.Config for defaulting, but don't actually use them
4343
cfg = &rest.Config{}
44-
45-
close(done)
4644
}, 60)

pkg/client/client_suite_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var testenv *envtest.Environment
4040
var cfg *rest.Config
4141
var clientset *kubernetes.Clientset
4242

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

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

5252
clientset, err = kubernetes.NewForConfig(cfg)
5353
Expect(err).NotTo(HaveOccurred())
54-
55-
close(done)
5654
}, 60)
5755

5856
var _ = AfterSuite(func() {

0 commit comments

Comments
 (0)