...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "context"
20
21 . "github.com/onsi/ginkgo/v2"
22 . "github.com/onsi/gomega"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/types"
25 )
26
27
28
29
30 var _ = Describe("AzureChaos", func() {
31 var (
32 key types.NamespacedName
33 created, fetched *AzureChaos
34 )
35
36 BeforeEach(func() {
37
38 })
39
40 AfterEach(func() {
41
42 })
43
44 Context("Create API", func() {
45 It("should create an object successfully", func() {
46 testSubscriptionID := "testSubscriptionID"
47 testResourceGroupName := "testResourceGroupName"
48 testVMName := "testVMName"
49
50 key = types.NamespacedName{
51 Name: "foo",
52 Namespace: "default",
53 }
54
55 created = &AzureChaos{
56 ObjectMeta: metav1.ObjectMeta{
57 Name: "foo",
58 Namespace: "default",
59 },
60 Spec: AzureChaosSpec{
61 Action: AzureVmStop,
62 AzureSelector: AzureSelector{
63 SubscriptionID: testSubscriptionID,
64 ResourceGroupName: testResourceGroupName,
65 VMName: testVMName,
66 },
67 },
68 }
69
70 By("creating an API obj")
71 Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
72
73 fetched = &AzureChaos{}
74 Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
75 Expect(fetched).To(Equal(created))
76
77 By("deleting the created object")
78 Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
79 Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
80 })
81 })
82 })
83