github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/registerer/registerer_test.go (about) 1 package registerer 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 . "github.com/smartystreets/goconvey/convey" 8 "go.aporeto.io/enforcerd/trireme-lib/common" 9 "go.aporeto.io/enforcerd/trireme-lib/monitor/processor/mockprocessor" 10 ) 11 12 func TestNew(t *testing.T) { 13 Convey("When I create a new registrer", t, func() { 14 r := New() 15 Convey("It should be valid", func() { 16 So(r, ShouldNotBeNil) 17 So(r.(*registerer).handlers, ShouldNotBeNil) 18 }) 19 }) 20 } 21 22 func TestRegisterProcessor(t *testing.T) { 23 ctrl := gomock.NewController(t) 24 defer ctrl.Finish() 25 26 Convey("When I register a new processor", t, func() { 27 r := New() 28 29 processor := mockprocessor.NewMockProcessor(ctrl) 30 err := r.RegisterProcessor(common.ContainerPU, processor) 31 32 Convey("The registration should be succesfull", func() { 33 So(err, ShouldBeNil) 34 h, ok := r.(*registerer).handlers[common.ContainerPU] 35 So(ok, ShouldBeTrue) 36 So(h, ShouldNotBeNil) 37 So(len(h), ShouldEqual, 6) 38 }) 39 40 Convey("If I ask for the handler, I should ge the right handler", func() { 41 _, err := r.GetHandler(common.ContainerPU, common.EventCreate) 42 So(err, ShouldBeNil) 43 44 _, err = r.GetHandler(common.ContainerPU, common.EventStart) 45 So(err, ShouldBeNil) 46 47 _, err = r.GetHandler(common.ContainerPU, common.EventDestroy) 48 So(err, ShouldBeNil) 49 50 _, err = r.GetHandler(common.ContainerPU, common.EventPause) 51 So(err, ShouldBeNil) 52 }) 53 54 Convey("If I ask for the handler with a bad PUType, I should get an error ", func() { 55 _, err := r.GetHandler(common.LinuxProcessPU, common.EventCreate) 56 So(err, ShouldNotBeNil) 57 }) 58 59 Convey("If I ask for the handler, with a bad event, I should get an error ", func() { 60 _, err := r.GetHandler(common.LinuxProcessPU, common.Event("300")) 61 So(err, ShouldNotBeNil) 62 }) 63 64 Convey("If I try to register the processor twice, I should get an error ", func() { 65 err := r.RegisterProcessor(common.ContainerPU, processor) 66 So(err, ShouldNotBeNil) 67 }) 68 }) 69 70 }