Skip to content

Commit 83c4cad

Browse files
committed
pkg,test: Update test fixtures that are instantiated with status fields
Update the adoption controller test subscription fixture and remove the status sub-resource block that's shared between tests. When an object is created, it's status sub-resource is now removed, so changes are centered around setting this resource before firing off any Update calls used throughout this test package. Update any test/e2e APIs that also follow a similiar pattern. Signed-off-by: timflannagan <[email protected]>
1 parent 363f1e0 commit 83c4cad

File tree

3 files changed

+249
-227
lines changed

3 files changed

+249
-227
lines changed

pkg/controller/operators/adoption_controller_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ var _ = Describe("Adoption Controller", func() {
8080
Spec: &operatorsv1alpha1.SubscriptionSpec{
8181
Package: "poultry",
8282
},
83-
Status: operatorsv1alpha1.SubscriptionStatus{
84-
InstalledCSV: "turkey",
85-
LastUpdated: metav1.Now(),
86-
},
8783
}
8884
sub.SetNamespace(ns.GetName())
8985
sub.SetName(sub.Spec.Package)
@@ -94,13 +90,14 @@ var _ = Describe("Adoption Controller", func() {
9490
created = append(created, sub)
9591

9692
// Set the Subscription's status separately
97-
status := sub.DeepCopy().Status
9893
Eventually(func() error {
9994
if err := k8sClient.Get(ctx, testobj.NamespacedName(sub), sub); err != nil {
10095
return err
10196
}
102-
sub.Status = status
103-
97+
sub.Status = operatorsv1alpha1.SubscriptionStatus{
98+
InstalledCSV: "turkey",
99+
LastUpdated: metav1.Now(),
100+
}
104101
return k8sClient.Status().Update(ctx, sub)
105102
}, timeout, interval).Should(Succeed())
106103

test/e2e/deprecated_e2e_test.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ var _ = Describe("Not found APIs", func() {
3030
// each entry is an installplan with a deprecated resource
3131
type payload struct {
3232
name string
33-
ip *operatorsv1alpha1.InstallPlan
33+
IP *operatorsv1alpha1.InstallPlan
3434
errMessage string
3535
}
3636

3737
var tableEntries []table.TableEntry
3838
tableEntries = []table.TableEntry{
3939
table.Entry("contains an entry with a missing API not found on cluster ", payload{
4040
name: "installplan contains a missing API",
41-
ip: &operatorsv1alpha1.InstallPlan{
41+
IP: &operatorsv1alpha1.InstallPlan{
4242
ObjectMeta: metav1.ObjectMeta{
4343
Namespace: *namespace, // this is necessary due to ginkgo table semantics, see https://github.com/onsi/ginkgo/issues/378
4444
Name: "test-plan-api",
@@ -48,41 +48,43 @@ var _ = Describe("Not found APIs", func() {
4848
Approved: true,
4949
ClusterServiceVersionNames: []string{},
5050
},
51-
Status: operatorsv1alpha1.InstallPlanStatus{
52-
Phase: operatorsv1alpha1.InstallPlanPhaseInstalling,
53-
CatalogSources: []string{},
54-
Plan: []*operatorsv1alpha1.Step{
55-
{
56-
Resolving: "test-csv",
57-
Status: operatorsv1alpha1.StepStatusUnknown,
58-
Resource: operatorsv1alpha1.StepResource{
59-
Name: "my.thing",
60-
Group: "verticalpodautoscalers.autoscaling.k8s.io",
61-
Version: "v1",
62-
Kind: "VerticalPodAutoscaler",
63-
Manifest: missingAPI,
64-
},
65-
},
66-
},
67-
},
6851
},
6952
errMessage: "api-server resource not found installing VerticalPodAutoscaler my.thing: GroupVersionKind " +
7053
"verticalpodautoscalers.autoscaling.k8s.io/v1, Kind=VerticalPodAutoscaler not found on the cluster",
7154
}),
7255
}
7356

7457
table.DescribeTable("the ip enters a failed state with a helpful error message", func(tt payload) {
75-
Expect(ctx.Ctx().Client().Create(context.Background(), tt.ip)).To(Succeed())
76-
Expect(ctx.Ctx().Client().Status().Update(context.Background(), tt.ip)).To(Succeed())
58+
Expect(ctx.Ctx().Client().Create(context.Background(), tt.IP)).To(Succeed())
59+
60+
tt.IP.Status = operatorsv1alpha1.InstallPlanStatus{
61+
Phase: operatorsv1alpha1.InstallPlanPhaseInstalling,
62+
CatalogSources: []string{},
63+
Plan: []*operatorsv1alpha1.Step{
64+
{
65+
Resolving: "test-csv",
66+
Status: operatorsv1alpha1.StepStatusUnknown,
67+
Resource: operatorsv1alpha1.StepResource{
68+
Name: "my.thing",
69+
Group: "verticalpodautoscalers.autoscaling.k8s.io",
70+
Version: "v1",
71+
Kind: "VerticalPodAutoscaler",
72+
Manifest: missingAPI,
73+
},
74+
},
75+
},
76+
}
77+
78+
Expect(ctx.Ctx().Client().Status().Update(context.Background(), tt.IP)).To(Succeed(), "failed to update the resource")
7779

7880
// The IP sits in the Installing phase with the GVK missing error
7981
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
80-
return tt.ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.ip), tt.ip)
82+
return tt.IP, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.IP), tt.IP)
8183
}).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseInstalling)), HaveMessage(tt.errMessage))
8284

8385
// Eventually the IP fails with the GVK missing error, after installplan retries, which is by default 1 minute.
8486
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
85-
return tt.ip, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.ip), tt.ip)
87+
return tt.IP, ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(tt.IP), tt.IP)
8688
}, 2*time.Minute).Should(And(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed)), HaveMessage(tt.errMessage))
8789
}, tableEntries...)
8890
})

0 commit comments

Comments
 (0)