Skip to content

Commit 7eb31f7

Browse files
authored
Merge pull request #4659 from kersten/fix/tests-avoid-shadowing-err-output-status
🌱 (chore): avoid shadowing of 'err' and related variables in E2E and external plugin tests
2 parents 1514289 + f7ae500 commit 7eb31f7

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

pkg/model/resource/resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ var _ = Describe("Resource", func() {
199199
webhookVersion = "v1"
200200
)
201201

202-
res := Resource{
202+
res = Resource{
203203
GVK: gvk,
204204
Plural: plural,
205205
Path: path,

pkg/plugins/external/external_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ var _ = Describe("Run external plugin using Scaffold", func() {
142142

143143
AfterEach(func() {
144144
filename := filepath.Join("tmp", "externalPlugin", "LICENSE")
145-
fileInfo, err := fs.FS.Stat(filename)
145+
var fileInfo os.FileInfo
146+
fileInfo, err = fs.FS.Stat(filename)
146147
Expect(err).ToNot(HaveOccurred())
147148
Expect(fileInfo).NotTo(BeNil())
148149
})

test/e2e/deployimage/plugin_cluster_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ func Run(kbc *utils.TestContext) {
100100
By("validating that the controller-manager pod is running as expected")
101101
verifyControllerUp := func(g Gomega) {
102102
// Get pod name
103-
podOutput, err := kbc.Kubectl.Get(
103+
var podOutput string
104+
podOutput, err = kbc.Kubectl.Get(
104105
true,
105106
"pods", "-l", "control-plane=controller-manager",
106107
"-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}"+
@@ -116,8 +117,8 @@ func Run(kbc *utils.TestContext) {
116117
To(Equal("Running"), "incorrect controller pod status")
117118
}
118119
defer func() {
119-
out, err := kbc.Kubectl.CommandInNamespace("describe", "all")
120-
Expect(err).NotTo(HaveOccurred())
120+
out, errDescribe := kbc.Kubectl.CommandInNamespace("describe", "all")
121+
Expect(errDescribe).NotTo(HaveOccurred())
121122
_, _ = fmt.Fprintln(GinkgoWriter, out)
122123
}()
123124
Eventually(verifyControllerUp).Should(Succeed())

test/e2e/v4/plugin_cluster_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
194194

195195
By("validating that the Prometheus manager has provisioned the Service")
196196
Eventually(func(g Gomega) {
197-
_, err := kbc.Kubectl.Get(
197+
_, err = kbc.Kubectl.Get(
198198
false,
199199
"Service", "prometheus-operator")
200200
g.Expect(err).NotTo(HaveOccurred())
@@ -208,7 +208,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
208208

209209
if hasNetworkPolicies {
210210
By("Checking for Calico pods")
211-
outputGet, err := kbc.Kubectl.Get(
211+
var outputGet string
212+
outputGet, err = kbc.Kubectl.Get(
212213
false,
213214
"pods",
214215
"-n", "kube-system",
@@ -224,7 +225,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
224225
"metrics=enabled")).Error().NotTo(HaveOccurred())
225226

226227
By("Ensuring the Allow Metrics Traffic NetworkPolicy exists", func() {
227-
output, err := kbc.Kubectl.Get(
228+
var output string
229+
output, err = kbc.Kubectl.Get(
228230
true,
229231
"networkpolicy", fmt.Sprintf("e2e-%s-allow-metrics-traffic", kbc.TestSuffix),
230232
)
@@ -241,7 +243,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
241243
Expect(err).NotTo(HaveOccurred())
242244

243245
By("Ensuring the allow-webhook-traffic NetworkPolicy exists", func() {
244-
output, err := kbc.Kubectl.Get(
246+
var output string
247+
output, err = kbc.Kubectl.Get(
245248
true,
246249
"networkpolicy", fmt.Sprintf("e2e-%s-allow-webhook-traffic", kbc.TestSuffix),
247250
)
@@ -256,7 +259,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
256259
By("validating that cert-manager has provisioned the certificate Secret")
257260

258261
verifyWebhookCert := func(g Gomega) {
259-
output, err := kbc.Kubectl.Get(
262+
var output string
263+
output, err = kbc.Kubectl.Get(
260264
true,
261265
"secrets", "webhook-server-cert")
262266
g.Expect(err).ToNot(HaveOccurred(), "webhook-server-cert should exist in the namespace")
@@ -267,7 +271,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
267271

268272
By("validating that the mutating|validating webhooks have the CA injected")
269273
verifyCAInjection := func(g Gomega) {
270-
mwhOutput, err := kbc.Kubectl.Get(
274+
var mwhOutput, vwhOutput string
275+
mwhOutput, err = kbc.Kubectl.Get(
271276
false,
272277
"mutatingwebhookconfigurations.admissionregistration.k8s.io",
273278
fmt.Sprintf("e2e-%s-mutating-webhook-configuration", kbc.TestSuffix),
@@ -276,7 +281,7 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
276281
// check that ca should be long enough, because there may be a place holder "\n"
277282
g.Expect(len(mwhOutput)).To(BeNumerically(">", 10))
278283

279-
vwhOutput, err := kbc.Kubectl.Get(
284+
vwhOutput, err = kbc.Kubectl.Get(
280285
false,
281286
"validatingwebhookconfigurations.admissionregistration.k8s.io",
282287
fmt.Sprintf("e2e-%s-validating-webhook-configuration", kbc.TestSuffix),
@@ -291,7 +296,8 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
291296
By("validating that the CA injection is applied for CRD conversion")
292297
crdKind := "ConversionTest"
293298
verifyCAInjection = func(g Gomega) {
294-
crdOutput, err := kbc.Kubectl.Get(
299+
var crdOutput string
300+
crdOutput, err = kbc.Kubectl.Get(
295301
false,
296302
"customresourcedefinition.apiextensions.k8s.io",
297303
"-o", fmt.Sprintf(
@@ -367,7 +373,7 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, isToUseHelmChart,
367373
By("applying the CR in the created namespace")
368374

369375
applySampleNamespaced := func(g Gomega) {
370-
_, err := kbc.Kubectl.Apply(false, "-n", namespace, "-f", sampleFile)
376+
_, err = kbc.Kubectl.Apply(false, "-n", namespace, "-f", sampleFile)
371377
g.Expect(err).To(Not(HaveOccurred()))
372378
}
373379
Eventually(applySampleNamespaced, 2*time.Minute, time.Second).Should(Succeed())
@@ -494,7 +500,8 @@ func getMetricsOutput(kbc *utils.TestContext) string {
494500

495501
By("ensuring the service endpoint is ready")
496502
checkServiceEndpoint := func(g Gomega) {
497-
output, err := kbc.Kubectl.Get(
503+
var output string
504+
output, err = kbc.Kubectl.Get(
498505
true,
499506
"endpoints", fmt.Sprintf("e2e-%s-controller-manager-metrics-service", kbc.TestSuffix),
500507
"-o", "jsonpath={.subsets[*].addresses[*].ip}",
@@ -512,7 +519,8 @@ func getMetricsOutput(kbc *utils.TestContext) string {
512519

513520
By("validating that the curl pod is running as expected")
514521
verifyCurlUp := func(g Gomega) {
515-
status, err := kbc.Kubectl.Get(
522+
var status string
523+
status, err = kbc.Kubectl.Get(
516524
true,
517525
"pods", "curl", "-o", "jsonpath={.status.phase}")
518526
g.Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)