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
85 lines (69 loc) · 2.92 KB
/
add_test.go
File metadata and controls
85 lines (69 loc) · 2.92 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
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package namespacedcloudprofile_test
import (
"context"
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/gardener/gardener/pkg/api/indexer"
"github.com/gardener/gardener/pkg/apis/core"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/gardener/gardener/pkg/client/kubernetes"
namespacedcloudprofilecontroller "github.com/gardener/gardener/pkg/controllermanager/controller/namespacedcloudprofile"
)
var _ = Describe("NamespacedCloudProfile controller", func() {
Describe("#MapCloudProfileToNamespacedCloudProfile", func() {
var (
ctx = context.TODO()
fakeClient client.Client
log = logr.Discard()
reconciler *namespacedcloudprofilecontroller.Reconciler
namespaceName string
cloudProfile *gardencorev1beta1.CloudProfile
namespacedCloudProfile *gardencorev1beta1.NamespacedCloudProfile
)
BeforeEach(func() {
fakeClient = fakeclient.NewClientBuilder().WithScheme(kubernetes.GardenScheme).WithIndex(
&gardencorev1beta1.NamespacedCloudProfile{},
core.NamespacedCloudProfileParentRefName,
indexer.NamespacedCloudProfileParentRefNameIndexerFunc,
).Build()
reconciler = &namespacedcloudprofilecontroller.Reconciler{Client: fakeClient, Recorder: &record.FakeRecorder{}}
namespaceName = "garden-test"
cloudProfile = &gardencorev1beta1.CloudProfile{
ObjectMeta: metav1.ObjectMeta{
Name: "test-profile",
},
}
namespacedCloudProfile = &gardencorev1beta1.NamespacedCloudProfile{
ObjectMeta: metav1.ObjectMeta{
Name: "n-profile-1",
Namespace: namespaceName,
},
Spec: gardencorev1beta1.NamespacedCloudProfileSpec{
Parent: gardencorev1beta1.CloudProfileReference{
Kind: "CloudProfile",
Name: cloudProfile.Name,
},
},
}
})
It("should successfully find all related NamespacedCloudProfiles referencing a CloudProfile", func() {
Expect(fakeClient.Create(ctx, cloudProfile)).To(Succeed())
Expect(fakeClient.Create(ctx, namespacedCloudProfile)).To(Succeed())
Expect(reconciler.MapCloudProfileToNamespacedCloudProfile(log)(ctx, cloudProfile)).To(ConsistOf(reconcile.Request{NamespacedName: types.NamespacedName{Name: "n-profile-1", Namespace: namespaceName}}))
})
It("should successfully return an empty result if no referencing NamespacedCloudProfiles exist", func() {
Expect(fakeClient.Create(ctx, cloudProfile)).To(Succeed())
Expect(reconciler.MapCloudProfileToNamespacedCloudProfile(log)(ctx, cloudProfile)).To(BeEmpty())
})
})
})