Skip to content

Commit a576624

Browse files
authored
unit tests-powervs (#339)
1 parent 92635f5 commit a576624

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/klog/v2/klogr"
24+
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/client"
26+
27+
"github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/api/v1alpha4"
28+
29+
. "github.com/onsi/ginkgo"
30+
. "github.com/onsi/gomega"
31+
32+
)
33+
34+
var _ = Describe("IBMPowerVSClusterReconciler", func() {
35+
36+
Context("Reconcile an IBMMPowerVSCluster", func() {
37+
It("should not error and not requeue the request", func() {
38+
ctx := context.Background()
39+
40+
reconciler := &IBMPowerVSClusterReconciler{
41+
Client: k8sClient,
42+
Log: klogr.New(),
43+
}
44+
45+
instance := &v1alpha4.IBMPowerVSCluster{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
46+
47+
// Create the IBMPowerVSCluster object and expect the Reconcile to be created
48+
Expect(k8sClient.Create(ctx, instance)).To(Succeed())
49+
defer func() {
50+
err := k8sClient.Delete(ctx, instance)
51+
Expect(err).NotTo(HaveOccurred())
52+
}()
53+
54+
result, err := reconciler.Reconcile(ctx, ctrl.Request{
55+
NamespacedName: client.ObjectKey{
56+
Namespace: instance.Namespace,
57+
Name: instance.Name,
58+
},
59+
})
60+
Expect(err).NotTo(HaveOccurred())
61+
Expect(result.RequeueAfter).To(BeZero())
62+
Expect(result.Requeue).To(BeFalse())
63+
})
64+
})
65+
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/klog/v2/klogr"
24+
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/client"
26+
27+
"github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/api/v1alpha4"
28+
29+
. "github.com/onsi/ginkgo"
30+
. "github.com/onsi/gomega"
31+
32+
)
33+
34+
var _ = Describe("IBMPowerVSMachineReconciler", func() {
35+
36+
Context("Reconcile an IBMPowerVSMachine", func() {
37+
It("should not error or requeue the request", func() {
38+
reconciler := &IBMPowerVSMachineReconciler{
39+
Client: k8sClient,
40+
Log: klogr.New(),
41+
}
42+
By("Calling reconcile")
43+
ctx := context.Background()
44+
instance := &v1alpha4.IBMPowerVSMachine{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
45+
result, err := reconciler.Reconcile(ctx, ctrl.Request{
46+
NamespacedName: client.ObjectKey{
47+
Namespace: instance.Namespace,
48+
Name: instance.Name,
49+
},
50+
})
51+
Expect(err).NotTo(HaveOccurred())
52+
Expect(result.RequeueAfter).To(BeZero())
53+
Expect(result.Requeue).To(BeFalse())
54+
})
55+
})
56+
})

0 commit comments

Comments
 (0)