...
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
49 func (e *testEndpoint) Apply(ctx context.Context, req ctrl.Request, chaos v1alpha1.InnerObject) error {
50 return nil
51 }
52
53 func (e *testEndpoint) Recover(ctx context.Context, req ctrl.Request, chaos v1alpha1.InnerObject) error {
54 return nil
55 }
56
57 func (e *testEndpoint) Object() v1alpha1.InnerObject {
58 return &v1alpha1.NetworkChaos{}
59 }
60
61 var _ = Describe("Router", func() {
62 It("should register successfully", func() {
63 Register("hello", &v1alpha1.NetworkChaos{}, func(obj runtime.Object) bool {
64 return true
65 }, func(ctx ctx.Context) end.Endpoint {
66 return &testEndpoint{}
67 })
68
69 Expect(len(routeTable)).To(Equal(1))
70
71 typ := reflect.TypeOf(&v1alpha1.NetworkChaos{})
72 Expect(routeTable[typ]).NotTo(BeNil())
73 })
74 })
75