...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package crclients
17
18 import (
19 "fmt"
20
21 . "github.com/onsi/ginkgo/v2"
22 . "github.com/onsi/gomega"
23 "github.com/pkg/errors"
24
25 "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/crclients/test"
26 "github.com/chaos-mesh/chaos-mesh/pkg/mock"
27 )
28
29 var _ = Describe("chaosdaemon util", func() {
30 Context("CreateContainerRuntimeInfoClient", func() {
31 It("should work without socket path", func() {
32 _, err := CreateContainerRuntimeInfoClient(&CrClientConfig{Runtime: ContainerRuntimeDocker})
33 Expect(err).To(BeNil())
34 _, err = CreateContainerRuntimeInfoClient(&CrClientConfig{Runtime: ContainerRuntimeDocker})
35 Expect(err).To(BeNil())
36 defer func() {
37 err := mock.With("MockContainerdClient", &test.MockClient{})()
38 Expect(err).To(BeNil())
39 }()
40 _, err = CreateContainerRuntimeInfoClient(&CrClientConfig{Runtime: ContainerRuntimeContainerd})
41 Expect(err).To(BeNil())
42 })
43
44 It("should work with socket path", func() {
45 _, err := CreateContainerRuntimeInfoClient(&CrClientConfig{Runtime: ContainerRuntimeDocker})
46 Expect(err).To(BeNil())
47 _, err = CreateContainerRuntimeInfoClient(&CrClientConfig{
48 Runtime: ContainerRuntimeDocker,
49 SocketPath: "/foo/bar/docker.socket"})
50 Expect(err).To(BeNil())
51 defer func() {
52 err := mock.With("MockContainerdClient", &test.MockClient{})()
53 Expect(err).To(BeNil())
54 }()
55 _, err = CreateContainerRuntimeInfoClient(&CrClientConfig{
56 Runtime: ContainerRuntimeContainerd,
57 SocketPath: "/foo/bar/containerd.socket"})
58 Expect(err).To(BeNil())
59 })
60
61 It("should work with socket path and ns", func() {
62 defer func() {
63 err := mock.With("MockContainerdClient", &test.MockClient{})()
64 Expect(err).To(BeNil())
65 }()
66 _, err := CreateContainerRuntimeInfoClient(&CrClientConfig{
67 Runtime: ContainerRuntimeContainerd,
68 SocketPath: "/foo/bar/containerd.socket",
69 ContainerdNS: "chaos-mesh.org"})
70 Expect(err).To(BeNil())
71 })
72
73 It("should error on newContaineredClient", func() {
74 errorStr := "this is a mocked error"
75
76 defer func() {
77 err := mock.With("NewContainerdClientError", errors.New(errorStr))()
78 Expect(err).To(BeNil())
79 }()
80 _, err := CreateContainerRuntimeInfoClient(&CrClientConfig{Runtime: ContainerRuntimeContainerd})
81 Expect(err).ToNot(BeNil())
82 Expect(fmt.Sprintf("%s", err)).To(Equal(errorStr))
83 })
84 })
85 })
86