Skip to content

Commit

Permalink
unit tests-powervs (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 authored Sep 13, 2021
1 parent 92635f5 commit a576624
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
65 changes: 65 additions & 0 deletions controllers/ibmpowervscluster_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/api/v1alpha4"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

)

var _ = Describe("IBMPowerVSClusterReconciler", func() {

Context("Reconcile an IBMMPowerVSCluster", func() {
It("should not error and not requeue the request", func() {
ctx := context.Background()

reconciler := &IBMPowerVSClusterReconciler{
Client: k8sClient,
Log: klogr.New(),
}

instance := &v1alpha4.IBMPowerVSCluster{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}

// Create the IBMPowerVSCluster object and expect the Reconcile to be created
Expect(k8sClient.Create(ctx, instance)).To(Succeed())
defer func() {
err := k8sClient.Delete(ctx, instance)
Expect(err).NotTo(HaveOccurred())
}()

result, err := reconciler.Reconcile(ctx, ctrl.Request{
NamespacedName: client.ObjectKey{
Namespace: instance.Namespace,
Name: instance.Name,
},
})
Expect(err).NotTo(HaveOccurred())
Expect(result.RequeueAfter).To(BeZero())
Expect(result.Requeue).To(BeFalse())
})
})
})
56 changes: 56 additions & 0 deletions controllers/ibmpowervsmachine_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/api/v1alpha4"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

)

var _ = Describe("IBMPowerVSMachineReconciler", func() {

Context("Reconcile an IBMPowerVSMachine", func() {
It("should not error or requeue the request", func() {
reconciler := &IBMPowerVSMachineReconciler{
Client: k8sClient,
Log: klogr.New(),
}
By("Calling reconcile")
ctx := context.Background()
instance := &v1alpha4.IBMPowerVSMachine{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
result, err := reconciler.Reconcile(ctx, ctrl.Request{
NamespacedName: client.ObjectKey{
Namespace: instance.Namespace,
Name: instance.Name,
},
})
Expect(err).NotTo(HaveOccurred())
Expect(result.RequeueAfter).To(BeZero())
Expect(result.Requeue).To(BeFalse())
})
})
})

0 comments on commit a576624

Please sign in to comment.