...
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 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/types"
25 )
26
27
28
29 var _ = Describe("StressChaos", func() {
30
31 Context("CRUD API", func() {
32 var (
33 key types.NamespacedName
34 created, fetched *StressChaos
35 )
36
37 It("Should create an object successfully", func() {
38 key = types.NamespacedName{
39 Name: "foo",
40 Namespace: "default",
41 }
42 created = &StressChaos{
43 ObjectMeta: v1.ObjectMeta{
44 Name: "foo",
45 Namespace: "default",
46 },
47 Spec: StressChaosSpec{
48 ContainerSelector: ContainerSelector{
49 PodSelector: PodSelector{
50 Mode: OneMode,
51 },
52 },
53 Stressors: &Stressors{MemoryStressor: &MemoryStressor{Stressor: Stressor{Workers: 1}}},
54 },
55 }
56 By("creating an API object")
57 Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())
58
59 fetched = &StressChaos{}
60 Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
61 Expect(fetched).To(Equal(created))
62
63 By("deleting the created object")
64 Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
65 Expect(k8sClient.Get(context.TODO(), key, created)).NotTo(Succeed())
66 })
67 })
68
69 })
70