github.com/lingyao2333/mo-zero@v1.4.1/core/breaker/nopbreaker_test.go (about) 1 package breaker 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestNopBreaker(t *testing.T) { 11 b := newNoOpBreaker() 12 assert.Equal(t, noOpBreakerName, b.Name()) 13 p, err := b.Allow() 14 assert.Nil(t, err) 15 p.Accept() 16 for i := 0; i < 1000; i++ { 17 p, err := b.Allow() 18 assert.Nil(t, err) 19 p.Reject("any") 20 } 21 assert.Nil(t, b.Do(func() error { 22 return nil 23 })) 24 assert.Nil(t, b.DoWithAcceptable(func() error { 25 return nil 26 }, defaultAcceptable)) 27 errDummy := errors.New("any") 28 assert.Equal(t, errDummy, b.DoWithFallback(func() error { 29 return errDummy 30 }, func(err error) error { 31 return nil 32 })) 33 assert.Equal(t, errDummy, b.DoWithFallbackAcceptable(func() error { 34 return errDummy 35 }, func(err error) error { 36 return nil 37 }, defaultAcceptable)) 38 }