...
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("JVMChaos", func() {
31 var (
32 key types.NamespacedName
33 created, fetched *JVMChaos
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 key = types.NamespacedName{
47 Name: "foo",
48 Namespace: "default",
49 }
50
51 created = &JVMChaos{
52 ObjectMeta: metav1.ObjectMeta{
53 Name: "foo",
54 Namespace: "default",
55 },
56 Spec: JVMChaosSpec{
57 Action: JVMLatencyAction,
58 JVMParameter: JVMParameter{
59 JVMClassMethodSpec: JVMClassMethodSpec{
60 Class: "Main",
61 Method: "print",
62 },
63 LatencyDuration: 1000,
64 },
65 ContainerSelector: ContainerSelector{
66 PodSelector: PodSelector{
67 Mode: OneMode,
68 },
69 },
70 },
71 }
72
73 By("creating an API obj")
74 Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
75
76 fetched = &JVMChaos{}
77 Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
78 Expect(fetched).To(Equal(created))
79
80 By("deleting the created object")
81 Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
82 Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
83 })
84 })
85 })
86