...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package chaosdaemon
15
16 import (
17 "context"
18 "errors"
19
20 . "github.com/onsi/ginkgo"
21 . "github.com/onsi/gomega"
22
23 "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/crclients"
24 "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/crclients/test"
25 pb "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
26 "github.com/chaos-mesh/chaos-mesh/pkg/mock"
27 )
28
29 var _ = Describe("container kill", func() {
30 defer mock.With("MockContainerdClient", &test.MockClient{})()
31 s, _ := newDaemonServer(crclients.ContainerRuntimeContainerd)
32
33 Context("ContainerKill", func() {
34 It("should work", func() {
35 _, err := s.ContainerKill(context.TODO(), &pb.ContainerRequest{
36 Action: &pb.ContainerAction{
37 Action: pb.ContainerAction_KILL,
38 },
39 ContainerId: "containerd://container-id",
40 })
41 Expect(err).To(BeNil())
42 })
43
44 It("should fail on wrong action type", func() {
45 const wrongActionType = 9527
46 _, err := s.ContainerKill(context.TODO(), &pb.ContainerRequest{
47 Action: &pb.ContainerAction{
48 Action: pb.ContainerAction_Action(wrongActionType),
49 },
50 ContainerId: "containerd://container-id",
51 })
52 Expect(err).ToNot(BeNil())
53 Expect(err.Error()).To(ContainSubstring("not kill"))
54 })
55
56 It("should fail on container kill", func() {
57 const errorStr = "mock error on container kill"
58 defer mock.With("KillError", errors.New(errorStr))()
59 _, err := s.ContainerKill(context.TODO(), &pb.ContainerRequest{
60 Action: &pb.ContainerAction{
61 Action: pb.ContainerAction_KILL,
62 },
63 ContainerId: "containerd://container-id",
64 })
65 Expect(err).ToNot(BeNil())
66 Expect(err.Error()).To(Equal(errorStr))
67 })
68 })
69 })
70