-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2802 from sedefsavas/unittests
🏃[KCP] Add integration and unit tests
- Loading branch information
Showing
6 changed files
with
502 additions
and
91 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_types_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
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 v1alpha3 | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
"golang.org/x/net/context" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3" | ||
) | ||
|
||
// These tests are written in BDD-style using Ginkgo framework. Refer to | ||
// http://onsi.github.io/ginkgo to learn more. | ||
|
||
var _ = Describe("KubeadmControlPlane", func() { | ||
var ( | ||
key types.NamespacedName | ||
created, fetched *KubeadmControlPlane | ||
ctx = context.TODO() | ||
) | ||
|
||
// Add Tests for OpenAPI validation (or additional CRD features) specified in | ||
// your API definition. | ||
// Avoid adding tests for vanilla CRUD operations because they would | ||
// test Kubernetes API server, which isn't the goal here. | ||
Context("Create API", func() { | ||
|
||
It("should create an object successfully", func() { | ||
|
||
key = types.NamespacedName{ | ||
Name: "foo", | ||
Namespace: "default", | ||
} | ||
|
||
// wrong version value | ||
created = &KubeadmControlPlane{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
Namespace: "default", | ||
}, | ||
Spec: KubeadmControlPlaneSpec{ | ||
InfrastructureTemplate: corev1.ObjectReference{}, | ||
Version: "1", | ||
KubeadmConfigSpec: cabpkv1.KubeadmConfigSpec{}, | ||
}, | ||
} | ||
|
||
By("creating an API obj with wrong version") | ||
Expect(k8sClient.Create(ctx, created)).NotTo(Succeed()) | ||
|
||
// missing field | ||
created2 := map[string]interface{}{ | ||
"kind": "KubeadmControlPlane", | ||
"apiVersion": "controlplane.cluster.x-k8s.io/v1alpha3", | ||
"metadata": map[string]interface{}{ | ||
"name": "foo", | ||
"namespace": "default", | ||
}, | ||
"spec": map[string]interface{}{ | ||
"version": "v1.1.1", | ||
}, | ||
} | ||
createdUnstructured := &unstructured.Unstructured{Object: created2} | ||
|
||
By("creating an API obj with missing field") | ||
Expect(k8sClient.Create(ctx, createdUnstructured)).NotTo(Succeed()) | ||
|
||
created = &KubeadmControlPlane{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
Namespace: "default", | ||
}, | ||
Spec: KubeadmControlPlaneSpec{ | ||
InfrastructureTemplate: corev1.ObjectReference{}, | ||
Version: "v1.1.1", | ||
KubeadmConfigSpec: cabpkv1.KubeadmConfigSpec{}, | ||
}, | ||
} | ||
|
||
By("creating an API obj") | ||
Expect(k8sClient.Create(ctx, created)).To(Succeed()) | ||
|
||
fetched = &KubeadmControlPlane{} | ||
Expect(k8sClient.Get(ctx, key, fetched)).To(Succeed()) | ||
Expect(fetched).To(Equal(created)) | ||
|
||
By("deleting the created object") | ||
Expect(k8sClient.Delete(ctx, created)).To(Succeed()) | ||
Expect(k8sClient.Get(ctx, key, created)).ToNot(Succeed()) | ||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.