Skip to content

Commit 9d6c6a9

Browse files
harsimranmaanbrandond
authored andcommitted
Address review comments
1 parent 3c5598c commit 9d6c6a9

10 files changed

+245
-246
lines changed

.golangci.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"exclude-files": [
1515
"/zz_generated_"
1616
],
17-
"deadline": "5m"
17+
"timeout": "5m"
1818
}
1919
}

e2e/suite/channel_resolve_test.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
"net/http"
66
"net/http/httptest"
77

8-
"github.com/onsi/ginkgo/v2"
9-
"github.com/onsi/gomega"
8+
. "github.com/onsi/ginkgo/v2" //nolint:revive
9+
. "github.com/onsi/gomega" //nolint:revive
1010
"github.com/rancher/system-upgrade-controller/e2e/framework"
1111
upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
1212
upgradeplan "github.com/rancher/system-upgrade-controller/pkg/upgrade/plan"
1313
)
1414

15-
var _ = ginkgo.Describe("Resolve channel", func() {
15+
var _ = Describe("Resolve channel", func() {
1616
e2e := framework.New("channel")
1717

18-
ginkgo.When("passed url fails to resolve", func() {
18+
When("passed url fails to resolve", func() {
1919
var (
2020
err error
2121
plan *upgradeapiv1.Plan
@@ -25,45 +25,45 @@ var _ = ginkgo.Describe("Resolve channel", func() {
2525
clusterID string
2626
latest string
2727
)
28-
ginkgo.BeforeEach(func() {
28+
BeforeEach(func() {
2929
ctx, cancel = context.WithCancel(context.Background())
3030
plan = e2e.NewPlan("channel-", "", nil)
3131
})
32-
ginkgo.AfterEach(func() {
32+
AfterEach(func() {
3333
if channelSrv != nil {
3434
channelSrv.Close()
3535
}
3636
cancel()
3737
})
38-
ginkgo.It("channel server is up with correct address", func() {
38+
It("channel server is up with correct address", func() {
3939
channelSrv = framework.ChannelServer("/local", http.StatusFound)
4040
plan.Spec.Channel = channelSrv.URL
41-
gomega.Expect(plan.Spec.Channel).ToNot(gomega.BeEmpty())
41+
Expect(plan.Spec.Channel).ToNot(BeEmpty())
4242
plan, err = e2e.CreatePlan(plan)
43-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
43+
Expect(err).ToNot(HaveOccurred())
4444
latest, err = upgradeplan.ResolveChannel(ctx, plan.Spec.Channel, plan.Status.LatestVersion, clusterID)
45-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
46-
gomega.Expect(latest).NotTo(gomega.BeEmpty())
45+
Expect(err).ToNot(HaveOccurred())
46+
Expect(latest).NotTo(BeEmpty())
4747
})
48-
ginkgo.It("channel server is up but url not found", func() {
48+
It("channel server is up but url not found", func() {
4949
channelSrv = framework.ChannelServer("/local", http.StatusNotFound)
5050
plan.Spec.Channel = channelSrv.URL
51-
gomega.Expect(plan.Spec.Channel).ToNot(gomega.BeEmpty())
51+
Expect(plan.Spec.Channel).ToNot(BeEmpty())
5252
plan, err = e2e.CreatePlan(plan)
53-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
53+
Expect(err).ToNot(HaveOccurred())
5454
latest, err = upgradeplan.ResolveChannel(ctx, plan.Spec.Channel, plan.Status.LatestVersion, clusterID)
55-
gomega.Expect(err).To(gomega.HaveOccurred())
56-
gomega.Expect(latest).To(gomega.BeEmpty())
55+
Expect(err).To(HaveOccurred())
56+
Expect(latest).To(BeEmpty())
5757
})
58-
ginkgo.It("Service Unavailable", func() {
58+
It("Service Unavailable", func() {
5959
channelSrv = framework.ChannelServer("/local", http.StatusServiceUnavailable)
6060
plan.Spec.Channel = channelSrv.URL
61-
gomega.Expect(plan.Spec.Channel).ToNot(gomega.BeEmpty())
61+
Expect(plan.Spec.Channel).ToNot(BeEmpty())
6262
plan, err = e2e.CreatePlan(plan)
63-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
63+
Expect(err).ToNot(HaveOccurred())
6464
latest, err = upgradeplan.ResolveChannel(ctx, plan.Spec.Channel, plan.Status.LatestVersion, clusterID)
65-
gomega.Expect(err).To(gomega.HaveOccurred())
66-
gomega.Expect(latest).To(gomega.BeEmpty())
65+
Expect(err).To(HaveOccurred())
66+
Expect(latest).To(BeEmpty())
6767
})
6868
})
6969
})

e2e/suite/job_generate_test.go

+60-60
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ import (
66
"io"
77
"time"
88

9+
. "github.com/onsi/ginkgo/v2" //nolint:revive
10+
. "github.com/onsi/gomega" //nolint:revive
911
batchv1 "k8s.io/api/batch/v1"
1012
v1 "k8s.io/api/core/v1"
11-
"k8s.io/utils/pointer"
13+
"k8s.io/utils/ptr"
1214

13-
"github.com/onsi/ginkgo/v2"
14-
"github.com/onsi/gomega"
1515
"github.com/rancher/system-upgrade-controller/e2e/framework"
1616
upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818
)
1919

20-
var _ = ginkgo.Describe("Job Generation", func() {
20+
var _ = Describe("Job Generation", func() {
2121
e2e := framework.New("generate")
2222

23-
ginkgo.When("fails because of a bad plan", func() {
23+
When("fails because of a bad plan", func() {
2424
var (
2525
err error
2626
plan *upgradeapiv1.Plan
2727
jobs []batchv1.Job
2828
)
29-
ginkgo.BeforeEach(func() {
29+
BeforeEach(func() {
3030
plan = e2e.NewPlan("fail-then-succeed-", "library/alpine:3.18", []string{"sh", "-c"}, "exit 1")
3131
plan.Spec.Version = "latest"
3232
plan.Spec.Concurrency = 1
@@ -38,54 +38,54 @@ var _ = ginkgo.Describe("Job Generation", func() {
3838
}},
3939
}
4040
plan, err = e2e.CreatePlan(plan)
41-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
41+
Expect(err).ToNot(HaveOccurred())
4242

4343
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 30*time.Second)
44-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
45-
gomega.Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(gomega.BeTrue())
44+
Expect(err).ToNot(HaveOccurred())
45+
Expect(upgradeapiv1.PlanLatestResolved.IsTrue(plan)).To(BeTrue())
4646

4747
jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second)
48-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
49-
gomega.Expect(jobs).To(gomega.HaveLen(1))
50-
gomega.Expect(jobs[0].Status.Succeeded).To(gomega.BeNumerically("==", 0))
51-
gomega.Expect(jobs[0].Status.Active).To(gomega.BeNumerically("==", 0))
52-
gomega.Expect(jobs[0].Status.Failed).To(gomega.BeNumerically(">=", 1))
48+
Expect(err).ToNot(HaveOccurred())
49+
Expect(jobs).To(HaveLen(1))
50+
Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 0))
51+
Expect(jobs[0].Status.Active).To(BeNumerically("==", 0))
52+
Expect(jobs[0].Status.Failed).To(BeNumerically(">=", 1))
5353

54-
gomega.Eventually(e2e.GetPlan).
54+
Eventually(e2e.GetPlan).
5555
WithArguments(plan.Name, metav1.GetOptions{}).
5656
WithTimeout(30 * time.Second).
57-
Should(gomega.WithTransform(upgradeapiv1.PlanComplete.IsTrue, gomega.BeFalse()))
57+
Should(WithTransform(upgradeapiv1.PlanComplete.IsTrue, BeFalse()))
5858

5959
plan, err = e2e.GetPlan(plan.Name, metav1.GetOptions{})
60-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
60+
Expect(err).ToNot(HaveOccurred())
6161
plan.Spec.Upgrade.Args = []string{"exit 0"}
6262
plan, err = e2e.UpdatePlan(plan)
63-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
63+
Expect(err).ToNot(HaveOccurred())
6464

6565
jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second)
66-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
67-
gomega.Expect(jobs).To(gomega.HaveLen(1))
66+
Expect(err).ToNot(HaveOccurred())
67+
Expect(jobs).To(HaveLen(1))
6868
})
69-
ginkgo.It("should apply successfully after edit", func() {
70-
gomega.Expect(jobs).To(gomega.HaveLen(1))
71-
gomega.Expect(jobs[0].Status.Succeeded).To(gomega.BeNumerically("==", 1))
72-
gomega.Expect(jobs[0].Status.Active).To(gomega.BeNumerically("==", 0))
73-
gomega.Expect(jobs[0].Status.Failed).To(gomega.BeNumerically("==", 0))
69+
It("should apply successfully after edit", func() {
70+
Expect(jobs).To(HaveLen(1))
71+
Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 1))
72+
Expect(jobs[0].Status.Active).To(BeNumerically("==", 0))
73+
Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0))
7474

75-
gomega.Eventually(e2e.GetPlan).
75+
Eventually(e2e.GetPlan).
7676
WithArguments(plan.Name, metav1.GetOptions{}).
7777
WithTimeout(30 * time.Second).
78-
Should(gomega.WithTransform(upgradeapiv1.PlanComplete.IsTrue, gomega.BeTrue()))
78+
Should(WithTransform(upgradeapiv1.PlanComplete.IsTrue, BeTrue()))
7979
})
8080
})
8181

82-
ginkgo.When("fails because of conflicting drain options", func() {
82+
When("fails because of conflicting drain options", func() {
8383
var (
8484
err error
8585
plan *upgradeapiv1.Plan
8686
jobs []batchv1.Job
8787
)
88-
ginkgo.BeforeEach(func() {
88+
BeforeEach(func() {
8989
plan = e2e.NewPlan("fail-drain-options-", "library/alpine:3.18", []string{"sh", "-c"}, "exit 0")
9090
plan.Spec.Version = "latest"
9191
plan.Spec.Concurrency = 1
@@ -98,8 +98,8 @@ var _ = ginkgo.Describe("Job Generation", func() {
9898
}
9999
plan.Spec.Drain = &upgradeapiv1.DrainSpec{
100100
DisableEviction: true,
101-
DeleteLocalData: pointer.Bool(true),
102-
DeleteEmptydirData: pointer.Bool(true),
101+
DeleteLocalData: ptr.To(true),
102+
DeleteEmptydirData: ptr.To(true),
103103
PodSelector: &metav1.LabelSelector{
104104
MatchExpressions: []metav1.LabelSelectorRequirement{{
105105
Key: "component",
@@ -109,36 +109,36 @@ var _ = ginkgo.Describe("Job Generation", func() {
109109
},
110110
}
111111
plan, err = e2e.CreatePlan(plan)
112-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
112+
Expect(err).ToNot(HaveOccurred())
113113

114114
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
115-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
116-
gomega.Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(gomega.BeFalse())
117-
gomega.Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(gomega.ContainSubstring("cannot specify both deleteEmptydirData and deleteLocalData"))
115+
Expect(err).ToNot(HaveOccurred())
116+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeFalse())
117+
Expect(upgradeapiv1.PlanSpecValidated.GetMessage(plan)).To(ContainSubstring("cannot specify both deleteEmptydirData and deleteLocalData"))
118118

119119
plan.Spec.Drain.DeleteLocalData = nil
120120
plan, err = e2e.UpdatePlan(plan)
121-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
121+
Expect(err).ToNot(HaveOccurred())
122122

123123
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanSpecValidated, 30*time.Second)
124-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
125-
gomega.Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(gomega.BeTrue())
124+
Expect(err).ToNot(HaveOccurred())
125+
Expect(upgradeapiv1.PlanSpecValidated.IsTrue(plan)).To(BeTrue())
126126

127127
jobs, err = e2e.WaitForPlanJobs(plan, 1, 120*time.Second)
128-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
129-
gomega.Expect(jobs).To(gomega.HaveLen(1))
128+
Expect(err).ToNot(HaveOccurred())
129+
Expect(jobs).To(HaveLen(1))
130130
})
131-
ginkgo.It("should apply successfully after edit", func() {
132-
gomega.Expect(jobs).To(gomega.HaveLen(1))
133-
gomega.Expect(jobs[0].Status.Succeeded).To(gomega.BeNumerically("==", 1))
134-
gomega.Expect(jobs[0].Status.Active).To(gomega.BeNumerically("==", 0))
135-
gomega.Expect(jobs[0].Status.Failed).To(gomega.BeNumerically("==", 0))
136-
gomega.Expect(jobs[0].Spec.Template.Spec.InitContainers).To(gomega.HaveLen(1))
137-
gomega.Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(gomega.ContainElement(gomega.ContainSubstring("!upgrade.cattle.io/controller")))
138-
gomega.Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(gomega.ContainElement(gomega.ContainSubstring("component notin (sonobuoy)")))
131+
It("should apply successfully after edit", func() {
132+
Expect(jobs).To(HaveLen(1))
133+
Expect(jobs[0].Status.Succeeded).To(BeNumerically("==", 1))
134+
Expect(jobs[0].Status.Active).To(BeNumerically("==", 0))
135+
Expect(jobs[0].Status.Failed).To(BeNumerically("==", 0))
136+
Expect(jobs[0].Spec.Template.Spec.InitContainers).To(HaveLen(1))
137+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("!upgrade.cattle.io/controller")))
138+
Expect(jobs[0].Spec.Template.Spec.InitContainers[0].Args).To(ContainElement(ContainSubstring("component notin (sonobuoy)")))
139139
})
140-
ginkgo.AfterEach(func() {
141-
if ginkgo.CurrentSpecReport().Failed() {
140+
AfterEach(func() {
141+
if CurrentSpecReport().Failed() {
142142
podList, _ := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).List(context.Background(), metav1.ListOptions{})
143143
for _, pod := range podList.Items {
144144
containerNames := []string{}
@@ -153,7 +153,7 @@ var _ = ginkgo.Describe("Job Generation", func() {
153153
logs := e2e.ClientSet.CoreV1().Pods(e2e.Namespace.Name).GetLogs(pod.Name, &v1.PodLogOptions{Container: container})
154154
if logStreamer, err := logs.Stream(context.Background()); err == nil {
155155
if podLogs, err := io.ReadAll(logStreamer); err == nil {
156-
ginkgo.AddReportEntry(reportName, string(podLogs))
156+
AddReportEntry(reportName, string(podLogs))
157157
}
158158
}
159159
}
@@ -162,22 +162,22 @@ var _ = ginkgo.Describe("Job Generation", func() {
162162
})
163163
})
164164

165-
ginkgo.When("updated secret should not change hash", func() {
165+
When("updated secret should not change hash", func() {
166166
var (
167167
err error
168168
plan *upgradeapiv1.Plan
169169
secret *v1.Secret
170170
hash string
171171
)
172-
ginkgo.BeforeEach(func() {
172+
BeforeEach(func() {
173173
secret, err = e2e.CreateSecret(&v1.Secret{
174174
ObjectMeta: metav1.ObjectMeta{
175175
Name: "test",
176176
Namespace: e2e.Namespace.Name,
177177
},
178178
Data: map[string][]byte{"config": []byte("test")},
179179
})
180-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
180+
Expect(err).ToNot(HaveOccurred())
181181

182182
plan = e2e.NewPlan("updated-secret-", "library/alpine:3.18", []string{"sh", "-c"}, "exit 0")
183183
plan.Spec.Version = "latest"
@@ -195,19 +195,19 @@ var _ = ginkgo.Describe("Job Generation", func() {
195195
IgnoreUpdates: true,
196196
}}
197197
plan, err = e2e.CreatePlan(plan)
198-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
198+
Expect(err).ToNot(HaveOccurred())
199199

200200
plan, err = e2e.WaitForPlanCondition(plan.Name, upgradeapiv1.PlanLatestResolved, 30*time.Second)
201-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
202-
gomega.Expect(plan.Status.LatestHash).ToNot(gomega.BeEmpty())
201+
Expect(err).ToNot(HaveOccurred())
202+
Expect(plan.Status.LatestHash).ToNot(BeEmpty())
203203
hash = plan.Status.LatestHash
204204

205205
secret.Data = map[string][]byte{"config": []byte("test2")}
206206
secret, err = e2e.UpdateSecret(secret)
207-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
207+
Expect(err).ToNot(HaveOccurred())
208208
})
209-
ginkgo.It("hash should be Equal", func() {
210-
gomega.Expect(plan.Status.LatestHash).Should(gomega.Equal(hash))
209+
It("hash should be equal", func() {
210+
Expect(plan.Status.LatestHash).Should(Equal(hash))
211211
})
212212
})
213213
})

e2e/suite/plan_create_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package suite_test
22

33
import (
4-
"github.com/onsi/ginkgo/v2"
5-
"github.com/onsi/gomega"
4+
. "github.com/onsi/ginkgo/v2" //nolint:revive
5+
. "github.com/onsi/gomega" //nolint:revive
66
"github.com/rancher/system-upgrade-controller/e2e/framework"
77
upgradeapiv1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
88
)
99

10-
var _ = ginkgo.Describe("Plan Creation", func() {
10+
var _ = Describe("Plan Creation", func() {
1111
e2e := framework.New("create")
12-
ginkgo.When("missing upgrade field", func() {
12+
When("missing upgrade field", func() {
1313
var (
1414
err error
1515
plan *upgradeapiv1.Plan
1616
)
17-
ginkgo.BeforeEach(func() {
17+
BeforeEach(func() {
1818
plan = e2e.NewPlan("upgrade", "", nil)
1919
plan.Spec.Upgrade = nil
2020
plan, err = e2e.CreatePlan(plan)
2121
})
22-
ginkgo.It("should return an error if upgrade in nil", func() {
23-
gomega.Expect(err).Should(gomega.HaveOccurred())
22+
It("should return an error if upgrade in nil", func() {
23+
Expect(err).Should(HaveOccurred())
2424
})
2525
})
2626
})

0 commit comments

Comments
 (0)