...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package router
15
16 import (
17 "context"
18 "math/rand"
19 "reflect"
20 "testing"
21
22 . "github.com/onsi/ginkgo"
23 . "github.com/onsi/gomega"
24 "k8s.io/apimachinery/pkg/runtime"
25 ctrl "sigs.k8s.io/controller-runtime"
26 "sigs.k8s.io/controller-runtime/pkg/envtest"
27
28 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
29 ctx "github.com/chaos-mesh/chaos-mesh/pkg/router/context"
30 end "github.com/chaos-mesh/chaos-mesh/pkg/router/endpoint"
31 )
32
33 func TestRouter(t *testing.T) {
34 RegisterFailHandler(Fail)
35
36 RunSpecsWithDefaultAndCustomReporters(t,
37 "Router Suit",
38 []Reporter{envtest.NewlineReporter{}})
39 }
40
41 var _ = BeforeSuite(func(done Done) {
42 rand.Seed(GinkgoRandomSeed())
43
44 close(done)
45 })
46
47 type testEndpoint struct {
48 output *string
49 }
50
51 func (e *testEndpoint) Apply(ctx context.Context, req ctrl.Request, chaos v1alpha1.InnerObject) error {
52 return nil
53 }
54
55 func (e *testEndpoint) Recover(ctx context.Context, req ctrl.Request, chaos v1alpha1.InnerObject) error {
56 return nil
57 }
58
59 func (e *testEndpoint) Object() v1alpha1.InnerObject {
60 return &v1alpha1.NetworkChaos{}
61 }
62
63 var _ = Describe("Router", func() {
64 It("should register successfully", func() {
65 Register("hello", &v1alpha1.NetworkChaos{}, func(obj runtime.Object) bool {
66 return true
67 }, func(ctx ctx.Context) end.Endpoint {
68 return &testEndpoint{}
69 })
70
71 Expect(len(routeTable)).To(Equal(1))
72
73 typ := reflect.TypeOf(&v1alpha1.NetworkChaos{})
74 Expect(routeTable[typ]).NotTo(BeNil())
75 })
76 })
77