Skip to content

Commit fc320a8

Browse files
authored
Merge pull request #2838 from LittleWat/patch-1
🐛 Nit: trim unncessary if check in templates/controllers/controller-test.go
2 parents 5e575cc + c592e6c commit fc320a8

File tree

5 files changed

+15
-65
lines changed

5 files changed

+15
-65
lines changed

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,13 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() {
135135
}
136136
137137
err = k8sClient.Create(ctx, {{ lower .Resource.Kind }})
138-
if err != nil {
139-
Expect(err).To(Not(HaveOccurred()))
140-
}
138+
Expect(err).To(Not(HaveOccurred()))
141139
}
142140
143141
By("Checking if the custom resource was successfully created")
144142
Eventually(func() error {
145143
found := &{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{}
146-
err = k8sClient.Get(ctx, typeNamespaceName, found)
147-
if err != nil {
148-
return err
149-
}
150-
return nil
144+
return k8sClient.Get(ctx, typeNamespaceName, found)
151145
}, time.Minute, time.Second).Should(Succeed())
152146
153147
By("Reconciling the custom resource created")
@@ -164,11 +158,7 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() {
164158
By("Checking if Deployment was successfully created in the reconciliation")
165159
Eventually(func() error {
166160
found := &appsv1.Deployment{}
167-
err = k8sClient.Get(ctx, typeNamespaceName, found)
168-
if err != nil {
169-
return err
170-
}
171-
return nil
161+
return k8sClient.Get(ctx, typeNamespaceName, found)
172162
}, time.Minute, time.Second).Should(Succeed())
173163
})
174164
})

testdata/project-v3-with-deploy-image/controllers/busybox_controller_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,13 @@ var _ = Describe("Busybox controller", func() {
8585
}
8686

8787
err = k8sClient.Create(ctx, busybox)
88-
if err != nil {
89-
Expect(err).To(Not(HaveOccurred()))
90-
}
88+
Expect(err).To(Not(HaveOccurred()))
9189
}
9290

9391
By("Checking if the custom resource was successfully created")
9492
Eventually(func() error {
9593
found := &examplecomv1alpha1.Busybox{}
96-
err = k8sClient.Get(ctx, typeNamespaceName, found)
97-
if err != nil {
98-
return err
99-
}
100-
return nil
94+
return k8sClient.Get(ctx, typeNamespaceName, found)
10195
}, time.Minute, time.Second).Should(Succeed())
10296

10397
By("Reconciling the custom resource created")
@@ -114,11 +108,7 @@ var _ = Describe("Busybox controller", func() {
114108
By("Checking if Deployment was successfully created in the reconciliation")
115109
Eventually(func() error {
116110
found := &appsv1.Deployment{}
117-
err = k8sClient.Get(ctx, typeNamespaceName, found)
118-
if err != nil {
119-
return err
120-
}
121-
return nil
111+
return k8sClient.Get(ctx, typeNamespaceName, found)
122112
}, time.Minute, time.Second).Should(Succeed())
123113
})
124114
})

testdata/project-v3-with-deploy-image/controllers/memcached_controller_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ var _ = Describe("Memcached controller", func() {
8686
}
8787

8888
err = k8sClient.Create(ctx, memcached)
89-
if err != nil {
90-
Expect(err).To(Not(HaveOccurred()))
91-
}
89+
Expect(err).To(Not(HaveOccurred()))
9290
}
9391

9492
By("Checking if the custom resource was successfully created")
9593
Eventually(func() error {
9694
found := &examplecomv1alpha1.Memcached{}
97-
err = k8sClient.Get(ctx, typeNamespaceName, found)
98-
if err != nil {
99-
return err
100-
}
101-
return nil
95+
return k8sClient.Get(ctx, typeNamespaceName, found)
10296
}, time.Minute, time.Second).Should(Succeed())
10397

10498
By("Reconciling the custom resource created")
@@ -115,11 +109,7 @@ var _ = Describe("Memcached controller", func() {
115109
By("Checking if Deployment was successfully created in the reconciliation")
116110
Eventually(func() error {
117111
found := &appsv1.Deployment{}
118-
err = k8sClient.Get(ctx, typeNamespaceName, found)
119-
if err != nil {
120-
return err
121-
}
122-
return nil
112+
return k8sClient.Get(ctx, typeNamespaceName, found)
123113
}, time.Minute, time.Second).Should(Succeed())
124114
})
125115
})

testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,13 @@ var _ = Describe("Busybox controller", func() {
8585
}
8686

8787
err = k8sClient.Create(ctx, busybox)
88-
if err != nil {
89-
Expect(err).To(Not(HaveOccurred()))
90-
}
88+
Expect(err).To(Not(HaveOccurred()))
9189
}
9290

9391
By("Checking if the custom resource was successfully created")
9492
Eventually(func() error {
9593
found := &examplecomv1alpha1.Busybox{}
96-
err = k8sClient.Get(ctx, typeNamespaceName, found)
97-
if err != nil {
98-
return err
99-
}
100-
return nil
94+
return k8sClient.Get(ctx, typeNamespaceName, found)
10195
}, time.Minute, time.Second).Should(Succeed())
10296

10397
By("Reconciling the custom resource created")
@@ -114,11 +108,7 @@ var _ = Describe("Busybox controller", func() {
114108
By("Checking if Deployment was successfully created in the reconciliation")
115109
Eventually(func() error {
116110
found := &appsv1.Deployment{}
117-
err = k8sClient.Get(ctx, typeNamespaceName, found)
118-
if err != nil {
119-
return err
120-
}
121-
return nil
111+
return k8sClient.Get(ctx, typeNamespaceName, found)
122112
}, time.Minute, time.Second).Should(Succeed())
123113
})
124114
})

testdata/project-v4-with-deploy-image/controllers/memcached_controller_test.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ var _ = Describe("Memcached controller", func() {
8686
}
8787

8888
err = k8sClient.Create(ctx, memcached)
89-
if err != nil {
90-
Expect(err).To(Not(HaveOccurred()))
91-
}
89+
Expect(err).To(Not(HaveOccurred()))
9290
}
9391

9492
By("Checking if the custom resource was successfully created")
9593
Eventually(func() error {
9694
found := &examplecomv1alpha1.Memcached{}
97-
err = k8sClient.Get(ctx, typeNamespaceName, found)
98-
if err != nil {
99-
return err
100-
}
101-
return nil
95+
return k8sClient.Get(ctx, typeNamespaceName, found)
10296
}, time.Minute, time.Second).Should(Succeed())
10397

10498
By("Reconciling the custom resource created")
@@ -115,11 +109,7 @@ var _ = Describe("Memcached controller", func() {
115109
By("Checking if Deployment was successfully created in the reconciliation")
116110
Eventually(func() error {
117111
found := &appsv1.Deployment{}
118-
err = k8sClient.Get(ctx, typeNamespaceName, found)
119-
if err != nil {
120-
return err
121-
}
122-
return nil
112+
return k8sClient.Get(ctx, typeNamespaceName, found)
123113
}, time.Minute, time.Second).Should(Succeed())
124114
})
125115
})

0 commit comments

Comments
 (0)