123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- package mon
- import (
- "context"
- "errors"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/wuntsong-org/go-zero-plus/core/breaker"
- "github.com/wuntsong-org/go-zero-plus/core/logx/logtest"
- "github.com/wuntsong-org/go-zero-plus/core/stringx"
- "github.com/wuntsong-org/go-zero-plus/core/timex"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "go.mongodb.org/mongo-driver/mongo"
- "go.mongodb.org/mongo-driver/mongo/integration/mtest"
- mopt "go.mongodb.org/mongo-driver/mongo/options"
- )
- var errDummy = errors.New("dummy")
- func TestKeepPromise_accept(t *testing.T) {
- p := new(mockPromise)
- kp := keepablePromise{
- promise: p,
- log: func(error) {},
- }
- assert.Nil(t, kp.accept(nil))
- assert.Equal(t, ErrNotFound, kp.accept(ErrNotFound))
- }
- func TestKeepPromise_keep(t *testing.T) {
- tests := []struct {
- err error
- accepted bool
- reason string
- }{
- {
- err: nil,
- accepted: true,
- reason: "",
- },
- {
- err: ErrNotFound,
- accepted: true,
- reason: "",
- },
- {
- err: errors.New("any"),
- accepted: false,
- reason: "any",
- },
- }
- for _, test := range tests {
- t.Run(stringx.RandId(), func(t *testing.T) {
- p := new(mockPromise)
- kp := keepablePromise{
- promise: p,
- log: func(error) {},
- }
- assert.Equal(t, test.err, kp.keep(test.err))
- assert.Equal(t, test.accepted, p.accepted)
- assert.Equal(t, test.reason, p.reason)
- })
- }
- }
- func TestNewCollection(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- coll := mt.Coll
- assert.NotNil(t, coll)
- col := newCollection(coll, breaker.GetBreaker("localhost"))
- assert.Equal(t, t.Name()+"/test", col.(*decoratedCollection).name)
- })
- }
- func TestCollection_Aggregate(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- coll := mt.Coll
- assert.NotNil(t, coll)
- col := newCollection(coll, breaker.GetBreaker("localhost"))
- ns := mt.Coll.Database().Name() + "." + mt.Coll.Name()
- aggRes := mtest.CreateCursorResponse(1, ns, mtest.FirstBatch)
- mt.AddMockResponses(aggRes)
- assert.Equal(t, t.Name()+"/test", col.(*decoratedCollection).name)
- cursor, err := col.Aggregate(context.Background(), mongo.Pipeline{}, mopt.Aggregate())
- assert.Nil(t, err)
- cursor.Close(context.Background())
- })
- }
- func TestCollection_BulkWrite(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
- res, err := c.BulkWrite(context.Background(), []mongo.WriteModel{
- mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}}),
- })
- assert.Nil(t, err)
- assert.NotNil(t, res)
- c.brk = new(dropBreaker)
- _, err = c.BulkWrite(context.Background(), []mongo.WriteModel{
- mongo.NewInsertOneModel().SetDocument(bson.D{{Key: "foo", Value: 1}}),
- })
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_CountDocuments(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateCursorResponse(
- 1,
- "DBName.CollectionName",
- mtest.FirstBatch,
- bson.D{
- {Key: "n", Value: 1},
- }))
- res, err := c.CountDocuments(context.Background(), bson.D{})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res)
- c.brk = new(dropBreaker)
- _, err = c.CountDocuments(context.Background(), bson.D{{Key: "foo", Value: 1}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestDecoratedCollection_DeleteMany(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- res, err := c.DeleteMany(context.Background(), bson.D{})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res.DeletedCount)
- c.brk = new(dropBreaker)
- _, err = c.DeleteMany(context.Background(), bson.D{{Key: "foo", Value: 1}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_Distinct(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(bson.D{{Key: "ok", Value: 1}, {Key: "values", Value: []int{1}}})
- resp, err := c.Distinct(context.Background(), "foo", bson.D{})
- assert.Nil(t, err)
- assert.Equal(t, 1, len(resp))
- c.brk = new(dropBreaker)
- _, err = c.Distinct(context.Background(), "foo", bson.D{{Key: "foo", Value: 1}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_EstimatedDocumentCount(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(bson.D{{Key: "ok", Value: 1}, {Key: "n", Value: 1}})
- res, err := c.EstimatedDocumentCount(context.Background())
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res)
- c.brk = new(dropBreaker)
- _, err = c.EstimatedDocumentCount(context.Background())
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_Find(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- find := mtest.CreateCursorResponse(
- 1,
- "DBName.CollectionName",
- mtest.FirstBatch,
- bson.D{
- {Key: "name", Value: "John"},
- })
- getMore := mtest.CreateCursorResponse(
- 1,
- "DBName.CollectionName",
- mtest.NextBatch,
- bson.D{
- {Key: "name", Value: "Mary"},
- })
- killCursors := mtest.CreateCursorResponse(
- 0,
- "DBName.CollectionName",
- mtest.NextBatch)
- mt.AddMockResponses(find, getMore, killCursors)
- filter := bson.D{{Key: "x", Value: 1}}
- cursor, err := c.Find(context.Background(), filter, mopt.Find())
- assert.Nil(t, err)
- defer cursor.Close(context.Background())
- var val []struct {
- ID primitive.ObjectID `bson:"_id"`
- Name string `bson:"name"`
- }
- assert.Nil(t, cursor.All(context.Background(), &val))
- assert.Equal(t, 2, len(val))
- assert.Equal(t, "John", val[0].Name)
- assert.Equal(t, "Mary", val[1].Name)
- c.brk = new(dropBreaker)
- _, err = c.Find(context.Background(), filter, mopt.Find())
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_FindOne(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- find := mtest.CreateCursorResponse(
- 1,
- "DBName.CollectionName",
- mtest.FirstBatch,
- bson.D{
- {Key: "name", Value: "John"},
- })
- getMore := mtest.CreateCursorResponse(
- 1,
- "DBName.CollectionName",
- mtest.NextBatch,
- bson.D{
- {Key: "name", Value: "Mary"},
- })
- killCursors := mtest.CreateCursorResponse(
- 0,
- "DBName.CollectionName",
- mtest.NextBatch)
- mt.AddMockResponses(find, getMore, killCursors)
- filter := bson.D{{Key: "x", Value: 1}}
- resp, err := c.FindOne(context.Background(), filter)
- assert.Nil(t, err)
- var val struct {
- ID primitive.ObjectID `bson:"_id"`
- Name string `bson:"name"`
- }
- assert.Nil(t, resp.Decode(&val))
- assert.Equal(t, "John", val.Name)
- c.brk = new(dropBreaker)
- _, err = c.FindOne(context.Background(), filter)
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_FindOneAndDelete(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- filter := bson.D{}
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{}...))
- _, err := c.FindOneAndDelete(context.Background(), filter, mopt.FindOneAndDelete())
- assert.Equal(t, mongo.ErrNoDocuments, err)
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{
- {Key: "value", Value: bson.D{{Key: "name", Value: "John"}}},
- }...))
- resp, err := c.FindOneAndDelete(context.Background(), filter, mopt.FindOneAndDelete())
- assert.Nil(t, err)
- var val struct {
- Name string `bson:"name"`
- }
- assert.Nil(t, resp.Decode(&val))
- assert.Equal(t, "John", val.Name)
- c.brk = new(dropBreaker)
- _, err = c.FindOneAndDelete(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_FindOneAndReplace(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{}...))
- filter := bson.D{{Key: "x", Value: 1}}
- replacement := bson.D{{Key: "x", Value: 2}}
- opts := mopt.FindOneAndReplace().SetUpsert(true)
- _, err := c.FindOneAndReplace(context.Background(), filter, replacement, opts)
- assert.Equal(t, mongo.ErrNoDocuments, err)
- mt.AddMockResponses(bson.D{{Key: "ok", Value: 1}, {Key: "value", Value: bson.D{
- {Key: "name", Value: "John"},
- }}})
- resp, err := c.FindOneAndReplace(context.Background(), filter, replacement, opts)
- assert.Nil(t, err)
- var val struct {
- Name string `bson:"name"`
- }
- assert.Nil(t, resp.Decode(&val))
- assert.Equal(t, "John", val.Name)
- c.brk = new(dropBreaker)
- _, err = c.FindOneAndReplace(context.Background(), filter, replacement, opts)
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_FindOneAndUpdate(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(bson.D{{Key: "ok", Value: 1}})
- filter := bson.D{{Key: "x", Value: 1}}
- update := bson.D{{Key: "$x", Value: 2}}
- opts := mopt.FindOneAndUpdate().SetUpsert(true)
- _, err := c.FindOneAndUpdate(context.Background(), filter, update, opts)
- assert.Equal(t, mongo.ErrNoDocuments, err)
- mt.AddMockResponses(bson.D{{Key: "ok", Value: 1}, {Key: "value", Value: bson.D{
- {Key: "name", Value: "John"},
- }}})
- resp, err := c.FindOneAndUpdate(context.Background(), filter, update, opts)
- assert.Nil(t, err)
- var val struct {
- Name string `bson:"name"`
- }
- assert.Nil(t, resp.Decode(&val))
- assert.Equal(t, "John", val.Name)
- c.brk = new(dropBreaker)
- _, err = c.FindOneAndUpdate(context.Background(), filter, update, opts)
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_InsertOne(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
- res, err := c.InsertOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Nil(t, err)
- assert.NotNil(t, res)
- c.brk = new(dropBreaker)
- _, err = c.InsertOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_InsertMany(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
- res, err := c.InsertMany(context.Background(), []any{
- bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "foo", Value: "baz"}},
- })
- assert.Nil(t, err)
- assert.NotNil(t, res)
- assert.Equal(t, 2, len(res.InsertedIDs))
- c.brk = new(dropBreaker)
- _, err = c.InsertMany(context.Background(), []any{bson.D{{Key: "foo", Value: "bar"}}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_DeleteOne(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- res, err := c.DeleteOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res.DeletedCount)
- c.brk = new(dropBreaker)
- _, err = c.DeleteOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_DeleteMany(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- res, err := c.DeleteMany(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res.DeletedCount)
- c.brk = new(dropBreaker)
- _, err = c.DeleteMany(context.Background(), bson.D{{Key: "foo", Value: "bar"}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_ReplaceOne(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- res, err := c.ReplaceOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "foo", Value: "baz"}},
- )
- assert.Nil(t, err)
- assert.Equal(t, int64(1), res.MatchedCount)
- c.brk = new(dropBreaker)
- _, err = c.ReplaceOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "foo", Value: "baz"}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_UpdateOne(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- resp, err := c.UpdateOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), resp.MatchedCount)
- c.brk = new(dropBreaker)
- _, err = c.UpdateOne(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_UpdateByID(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- resp, err := c.UpdateByID(context.Background(), primitive.NewObjectID(),
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), resp.MatchedCount)
- c.brk = new(dropBreaker)
- _, err = c.UpdateByID(context.Background(), primitive.NewObjectID(),
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestCollection_UpdateMany(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- mt.Run("test", func(mt *mtest.T) {
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "n", Value: 1}}...))
- resp, err := c.UpdateMany(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Nil(t, err)
- assert.Equal(t, int64(1), resp.MatchedCount)
- c.brk = new(dropBreaker)
- _, err = c.UpdateMany(context.Background(), bson.D{{Key: "foo", Value: "bar"}},
- bson.D{{Key: "$set", Value: bson.D{{Key: "baz", Value: "qux"}}}})
- assert.Equal(t, errDummy, err)
- })
- }
- func TestDecoratedCollection_LogDuration(t *testing.T) {
- mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
- c := decoratedCollection{
- Collection: mt.Coll,
- brk: breaker.NewBreaker(),
- }
- buf := logtest.NewCollector(t)
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now(), nil, "bar")
- assert.Contains(t, buf.String(), "foo")
- assert.Contains(t, buf.String(), "bar")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now(), errors.New("bar"), make(chan int))
- assert.Contains(t, buf.String(), "foo")
- assert.Contains(t, buf.String(), "bar")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now(), nil, make(chan int))
- assert.Contains(t, buf.String(), "foo")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now()-slowThreshold.Load()*2,
- nil, make(chan int))
- assert.Contains(t, buf.String(), "foo")
- assert.Contains(t, buf.String(), "slowcall")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now()-slowThreshold.Load()*2,
- errors.New("bar"), make(chan int))
- assert.Contains(t, buf.String(), "foo")
- assert.Contains(t, buf.String(), "bar")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now()-slowThreshold.Load()*2,
- errors.New("bar"))
- assert.Contains(t, buf.String(), "foo")
- buf.Reset()
- c.logDuration(context.Background(), "foo", timex.Now()-slowThreshold.Load()*2, nil)
- assert.Contains(t, buf.String(), "foo")
- assert.Contains(t, buf.String(), "slowcall")
- }
- type mockPromise struct {
- accepted bool
- reason string
- }
- func (p *mockPromise) Accept() {
- p.accepted = true
- }
- func (p *mockPromise) Reject(reason string) {
- p.reason = reason
- }
- type dropBreaker struct{}
- func (d *dropBreaker) Name() string {
- return "dummy"
- }
- func (d *dropBreaker) Allow() (breaker.Promise, error) {
- return nil, errDummy
- }
- func (d *dropBreaker) Do(_ func() error) error {
- return nil
- }
- func (d *dropBreaker) DoWithAcceptable(_ func() error, _ breaker.Acceptable) error {
- return errDummy
- }
- func (d *dropBreaker) DoWithFallback(_ func() error, _ func(err error) error) error {
- return nil
- }
- func (d *dropBreaker) DoWithFallbackAcceptable(_ func() error, _ func(err error) error,
- _ breaker.Acceptable) error {
- return nil
- }
|