github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/pkg/counters/default_test.go (about) 1 package counters 2 3 import ( 4 "errors" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 ) 9 10 func Test_DefaultCounterError(t *testing.T) { 11 12 Convey("When I increment counter", t, func() { 13 err := CounterError(ErrInvalidProtocol, errors.New("unknown protocol")) 14 IncrementCounter(ErrInvalidProtocol) 15 So(err, ShouldResemble, errors.New("unknown protocol")) 16 So(defaultCounters.counters[ErrInvalidProtocol], ShouldEqual, 2) 17 18 // Reset the global counters 19 GetErrorCounters() // nolint 20 }) 21 } 22 23 func Test_DefaultGetErrorCounter(t *testing.T) { 24 25 Convey("When I increment counter", t, func() { 26 err := CounterError(ErrInvalidProtocol, errors.New("unknown protocol")) 27 IncrementCounter(ErrInvalidProtocol) 28 IncrementCounter(ErrInvalidProtocol) 29 So(err, ShouldResemble, errors.New("unknown protocol")) 30 So(defaultCounters.counters[ErrInvalidProtocol], ShouldEqual, 3) 31 32 Convey("When I get the error counter", func() { 33 c := GetErrorCounters() 34 So(len(c), ShouldEqual, errMax) 35 So(c[ErrInvalidProtocol], ShouldEqual, 3) 36 So(defaultCounters.counters[ErrInvalidProtocol], ShouldEqual, 0) 37 }) 38 }) 39 }