Repository: zeromicro/go-zero
Pull request #2769 (2023-01-09 00:26:39)

feat: replace NewBetchInserter function name

codecov-commenter: # [Codecov](https://codecov.io/gh/zeromicro/go-zero/pull/2769?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#2769](https://codecov.io/gh/zeromicro/go-zero/pull/2769?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (b3e1f15) into [master](https://codecov.io/gh/zeromicro/go-zero/commit/0c786ca8492907d09d4b118dbd6855e86f32372a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (0c786ca) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head b3e1f15 differs from pull request most recent head 59a28e6. Consider uploading reports for the commit 59a28e6 to get more accurate results


| [Impacted Files](https://codecov.io/gh/zeromicro/go-zero/pull/2769?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/stores/mon/bulkinserter.go](https://codecov.io/gh/zeromicro/go-zero/pull/2769?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9zdG9yZXMvbW9uL2J1bGtpbnNlcnRlci5nbw==) | `73.33% <100.00%> (-1.14%)` | :arrow_down: |
| [core/logx/rotatelogger.go](https://codecov.io/gh/zeromicro/go-zero/pull/2769?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9sb2d4L3JvdGF0ZWxvZ2dlci5nbw==) | `72.69% <0.00%> (-1.11%)` | :arrow_down: |


Patch:
diff --git a/core/stores/mon/bulkinserter.go b/core/stores/mon/bulkinserter.go
index 74cbb7d9..7ef15ca5 100644
--- a/core/stores/mon/bulkinserter.go
+++ b/core/stores/mon/bulkinserter.go
@@ -25,25 +25,15 @@ type (
 	}
 )
 
-// Deprecated. Use NewBatchInserter instead.
-func NewBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
-	return newBulkInserter(coll, interval...)
-}
-
-// NewBatchInserter returns a BulkInserter.
-func NewBatchInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) {
+// NewBulkInserter returns a BulkInserter.
+func NewBulkInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) {
 	cloneColl, err := coll.Clone()
 	if err != nil {
 		return nil, err
 	}
 
-	return newBulkInserter(cloneColl, interval...), nil
-}
-
-// newBulkInserter returns a BulkInserter.
-func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
 	inserter := &dbInserter{
-		collection: coll,
+		collection: cloneColl,
 	}
 
 	duration := flushInterval
@@ -54,7 +44,7 @@ func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkIns
 	return &BulkInserter{
 		executor: executors.NewPeriodicalExecutor(duration, inserter),
 		inserter: inserter,
-	}
+	}, nil
 }
 
 // Flush flushes the inserter, writes all pending records.


Test patch:
diff --git a/core/stores/mon/bulkinserter_test.go b/core/stores/mon/bulkinserter_test.go
index f2889d35..ebd0ec4a 100644
--- a/core/stores/mon/bulkinserter_test.go
+++ b/core/stores/mon/bulkinserter_test.go
@@ -15,24 +15,7 @@ func TestBulkInserter(t *testing.T) {
 
 	mt.Run("test", func(mt *mtest.T) {
 		mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
-		bulk := NewBulkInserter(mt.Coll)
-		bulk.SetResultHandler(func(result *mongo.InsertManyResult, err error) {
-			assert.Nil(t, err)
-			assert.Equal(t, 2, len(result.InsertedIDs))
-		})
-		bulk.Insert(bson.D{{Key: "foo", Value: "bar"}})
-		bulk.Insert(bson.D{{Key: "foo", Value: "baz"}})
-		bulk.Flush()
-	})
-}
-
-func TestBatchInserter(t *testing.T) {
-	mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
-	defer mt.Close()
-
-	mt.Run("test", func(mt *mtest.T) {
-		mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...))
-		bulk, err := NewBatchInserter(createModel(mt).Collection)
+		bulk, err := NewBulkInserter(createModel(mt).Collection)
 		assert.Equal(t, err, nil)
 		bulk.SetResultHandler(func(result *mongo.InsertManyResult, err error) {
 			assert.Nil(t, err)