...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "context"
20 "time"
21
22 . "github.com/onsi/ginkgo/v2"
23 . "github.com/onsi/gomega"
24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25 "k8s.io/apimachinery/pkg/types"
26 )
27
28
29
30
31 var _ = Describe("Schedule", func() {
32 var (
33 key types.NamespacedName
34 created, fetched *Schedule
35 )
36
37 BeforeEach(func() {
38
39 })
40
41 AfterEach(func() {
42
43 })
44
45 Context("Create API", func() {
46 It("should create an object successfully", func() {
47 key = types.NamespacedName{
48 Name: "foo",
49 Namespace: "default",
50 }
51
52 created = &Schedule{
53 ObjectMeta: metav1.ObjectMeta{
54 Name: "foo",
55 Namespace: "default",
56 },
57 Spec: ScheduleSpec{
58 Schedule: "* * * * 1",
59 ScheduleItem: ScheduleItem{
60 EmbedChaos: EmbedChaos{PodChaos: &PodChaosSpec{
61 Action: PodKillAction,
62 ContainerSelector: ContainerSelector{
63 PodSelector: PodSelector{
64 Mode: OneMode,
65 },
66 },
67 },
68 },
69 },
70 ConcurrencyPolicy: ForbidConcurrent,
71 Type: ScheduleTypePodChaos,
72 },
73 Status: ScheduleStatus{
74 LastScheduleTime: metav1.Time{Time: time.Now()},
75 },
76 }
77
78 By("creating an API obj")
79 Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
80
81 fetched = &Schedule{}
82 Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
83 Expect(fetched).To(Equal(created))
84
85 By("deleting the created object")
86 Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
87 Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
88 })
89 })
90 })
91