forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_test.go
More file actions
110 lines (87 loc) · 3.31 KB
/
add_test.go
File metadata and controls
110 lines (87 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package migration_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
. "github.com/gardener/gardener/pkg/controllermanager/controller/shoot/migration"
)
var _ = Describe("Add", func() {
var reconciler *Reconciler
BeforeEach(func() {
reconciler = &Reconciler{}
})
Describe("#ShootPredicate", func() {
var (
predicate predicate.Predicate
shoot *gardencorev1beta1.Shoot
)
BeforeEach(func() {
predicate = reconciler.ShootPredicate()
shoot = &gardencorev1beta1.Shoot{
Spec: gardencorev1beta1.ShootSpec{
SeedName: ptr.To("seed-1"),
},
Status: gardencorev1beta1.ShootStatus{
SeedName: ptr.To("seed-1"),
},
}
})
Describe("#Create", func() {
It("should return false because shoot is not being migration", func() {
Expect(predicate.Create(event.CreateEvent{Object: shoot})).To(BeFalse())
})
It("should return true because shoot needs migration", func() {
shoot.Spec.SeedName = ptr.To("seed-2")
Expect(predicate.Create(event.CreateEvent{Object: shoot})).To(BeTrue())
})
It("should return true because constraint is still present after migration", func() {
shoot.Status.Constraints = []gardencorev1beta1.Condition{
{Type: "ReadyForMigration"},
}
shoot.Status.LastOperation = &gardencorev1beta1.LastOperation{
Type: gardencorev1beta1.LastOperationTypeReconcile,
}
Expect(predicate.Create(event.CreateEvent{Object: shoot})).To(BeTrue())
})
})
Describe("#Update", func() {
var shootNew *gardencorev1beta1.Shoot
BeforeEach(func() {
shootNew = shoot.DeepCopy()
})
It("should return false because seed name is unchanged", func() {
Expect(predicate.Update(event.UpdateEvent{ObjectNew: shoot, ObjectOld: shoot})).To(BeFalse())
})
It("should return true because seed name is changed", func() {
shootNew.Spec.SeedName = ptr.To("seed-2")
Expect(predicate.Update(event.UpdateEvent{ObjectNew: shootNew, ObjectOld: shoot})).To(BeTrue())
})
It("should return false because constraint is present during migration", func() {
shootNew.Status.Constraints = []gardencorev1beta1.Condition{{Type: "ReadyForMigration"}}
shootNew.Status.LastOperation = &gardencorev1beta1.LastOperation{Type: "Migrate"}
Expect(predicate.Update(event.UpdateEvent{ObjectNew: shootNew, ObjectOld: shoot})).To(BeFalse())
})
It("should return true because constraint it present during restore", func() {
shootNew.Status.Constraints = []gardencorev1beta1.Condition{{Type: "ReadyForMigration"}}
shootNew.Status.LastOperation = &gardencorev1beta1.LastOperation{Type: "Restore"}
Expect(predicate.Update(event.UpdateEvent{ObjectNew: shootNew, ObjectOld: shoot})).To(BeTrue())
})
})
Describe("#Delete", func() {
It("should always return false", func() {
Expect(predicate.Delete(event.DeleteEvent{})).To(BeFalse())
})
})
Describe("#Generic", func() {
It("should always return false", func() {
Expect(predicate.Generic(event.GenericEvent{})).To(BeFalse())
})
})
})
})