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
77 lines (61 loc) · 1.95 KB
/
add_test.go
File metadata and controls
77 lines (61 loc) · 1.95 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
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package state_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/gardenlet/controller/shoot/state"
)
var _ = Describe("Add", func() {
var (
reconciler *Reconciler
shoot *gardencorev1beta1.Shoot
seedName = "seed"
)
BeforeEach(func() {
reconciler = &Reconciler{SeedName: seedName}
shoot = &gardencorev1beta1.Shoot{}
})
Describe("#SeedNameChangedPredicate", func() {
var p predicate.Predicate
BeforeEach(func() {
p = reconciler.SeedNameChangedPredicate()
})
Describe("#Create", func() {
It("should return true", func() {
Expect(p.Create(event.CreateEvent{})).To(BeTrue())
})
})
Describe("#Update", func() {
It("should return false because new object is no shoot", func() {
Expect(p.Update(event.UpdateEvent{})).To(BeFalse())
})
It("should return false because old object is no shoot", func() {
Expect(p.Update(event.UpdateEvent{ObjectNew: shoot})).To(BeFalse())
})
It("should return false because seed name is equal", func() {
Expect(p.Update(event.UpdateEvent{ObjectNew: shoot, ObjectOld: shoot})).To(BeFalse())
})
It("should return true because seed name changed", func() {
oldShoot := shoot.DeepCopy()
shoot.Spec.SeedName = ptr.To("new-seed")
Expect(p.Update(event.UpdateEvent{ObjectNew: shoot, ObjectOld: oldShoot})).To(BeTrue())
})
})
Describe("#Delete", func() {
It("should return true", func() {
Expect(p.Delete(event.DeleteEvent{})).To(BeTrue())
})
})
Describe("#Generic", func() {
It("should return true", func() {
Expect(p.Generic(event.GenericEvent{})).To(BeTrue())
})
})
})
})