Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/reconcile coverage #481

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand Down
100 changes: 100 additions & 0 deletions controllers/meshsync_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright 2020 Layer5, Inc.

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"

"github.com/layer5io/meshery-operator/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
)

var _ = Describe("The test cases for customize resource: MeshSync's controller ", func() {

var (
namespace string
ctx context.Context
)

BeforeEach(func() {
ctx = context.Background()
})

Context("Testing meshSync's nothing found logic", func() {
It("Getting meshSync resource should be failing", func() {
namespace = "default"
meshSync := &v1alpha1.MeshSync{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "default", Namespace: namespace}, meshSync)
Expect(err).To(HaveOccurred())
})
})

It("Creating a meshSync resource", func() {
namespace = "default"
meshSync := &v1alpha1.MeshSync{
TypeMeta: metav1.TypeMeta{
APIVersion: "meshery.layer5.io/v1alpha1",
Kind: "MeshSync",
},
ObjectMeta: metav1.ObjectMeta{
Name: "default",
Namespace: namespace,
},
Spec: v1alpha1.MeshSyncSpec{
Size: 1,
}}

Expect(k8sClient.Create(ctx, meshSync)).Should(Succeed())
})

It("Getting meshSync resource should be successful", func() {
namespace = "default"
meshSync := &v1alpha1.MeshSync{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "default", Namespace: namespace}, meshSync)
Expect(err).ToNot(HaveOccurred())
Expect(meshSync.Spec.Size).To(Equal(int32(1)))
})

It("Updating meshSync resource should be successful", func() {
namespace = "default"
meshSync := &v1alpha1.MeshSync{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "default", Namespace: namespace}, meshSync)
Expect(err).ToNot(HaveOccurred())
meshSync.Spec.Size = 2
Expect(k8sClient.Update(ctx, meshSync)).Should(Succeed())

By("Checking if the meshSync resource is updated")
meshSync = &v1alpha1.MeshSync{}
err = k8sClient.Get(ctx, types.NamespacedName{Name: "default", Namespace: namespace}, meshSync)
Expect(err).ToNot(HaveOccurred())
Expect(meshSync.Spec.Size).To(Equal(int32(2)))
})

Context("Testing MeshSync's Cleanup logic", func() {
It("Deleting meshSync resource should be succeeding", func() {
namespace = "default"
meshSync := &v1alpha1.MeshSync{}
err := k8sClient.Get(ctx, types.NamespacedName{Name: "default", Namespace: namespace}, meshSync)
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient.Delete(ctx, meshSync)).Should(Succeed())
})
})

})
11 changes: 11 additions & 0 deletions controllers/suit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ var _ = BeforeSuite(func(ctx SpecContext) {
err = brokerReconciler.SetupWithManager(mgr)
Expect(err).ToNot(HaveOccurred())

meshSyncReconciler := &MeshSyncReconciler{
Client: mgr.GetClient(),
KubeConfig: cfg,
Clientset: clientSet,
Log: ctrl.Log.WithName("controllers").WithName("Broker"),
Scheme: mgr.GetScheme(),
}

err = meshSyncReconciler.SetupWithManager(mgr)
Expect(err).ToNot(HaveOccurred())

// +kubebuilder:scaffold:builder
go func() {
defer GinkgoRecover()
Expand Down