Skip to content

Commit f0298af

Browse files
refactor(build/aggregation): naming optimization (#32)
* refactor(build/aggregation): rename the Builder's AddKeyValues method to KeyValue. * refactor(build/aggregation): rename the BsonBuilder function to NewBuilder.
1 parent 17531d2 commit f0298af

11 files changed

+131
-131
lines changed

builder/aggregation/accumulators_builder_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323

2424
func Test_accumulatorsBuilder_Sum(t *testing.T) {
2525
t.Run("single operation", func(t *testing.T) {
26-
assert.Equal(t, bson.D{bson.E{Key: "totalAmount", Value: bson.D{{Key: "$sum", Value: "$price"}}}}, BsonBuilder().Sum("totalAmount", "$price").Build())
26+
assert.Equal(t, bson.D{bson.E{Key: "totalAmount", Value: bson.D{{Key: "$sum", Value: "$price"}}}}, NewBuilder().Sum("totalAmount", "$price").Build())
2727
})
2828
t.Run("multiple operations", func(t *testing.T) {
29-
assert.Equal(t, bson.D{bson.E{Key: "totalAmount", Value: bson.D{{Key: "$sum", Value: "$price"}}}, bson.E{Key: "totalFee", Value: bson.D{{Key: "$sum", Value: "$fee"}}}}, BsonBuilder().Sum("totalAmount", "$price").Sum("totalFee", "$fee").Build())
29+
assert.Equal(t, bson.D{bson.E{Key: "totalAmount", Value: bson.D{{Key: "$sum", Value: "$price"}}}, bson.E{Key: "totalFee", Value: bson.D{{Key: "$sum", Value: "$fee"}}}}, NewBuilder().Sum("totalAmount", "$price").Sum("totalFee", "$fee").Build())
3030
})
3131
}
3232

@@ -44,17 +44,17 @@ func Test_accumulatorsBuilder_SumWithoutKey(t *testing.T) {
4444
}
4545
for _, tc := range testCases {
4646
t.Run(tc.name, func(t *testing.T) {
47-
assert.Equal(t, tc.expected, BsonBuilder().SumWithoutKey(tc.expression).Build())
47+
assert.Equal(t, tc.expected, NewBuilder().SumWithoutKey(tc.expression).Build())
4848
})
4949
}
5050
}
5151

5252
func Test_accumulatorsBuilder_Push(t *testing.T) {
5353
t.Run("single operation", func(t *testing.T) {
54-
assert.Equal(t, bson.D{bson.E{Key: "items", Value: bson.D{{Key: "$push", Value: "$item"}}}}, BsonBuilder().Push("items", "$item").Build())
54+
assert.Equal(t, bson.D{bson.E{Key: "items", Value: bson.D{{Key: "$push", Value: "$item"}}}}, NewBuilder().Push("items", "$item").Build())
5555
})
5656
t.Run("multiple operations", func(t *testing.T) {
57-
assert.Equal(t, bson.D{bson.E{Key: "items", Value: bson.D{{Key: "$push", Value: "$item"}}}, bson.E{Key: "types", Value: bson.D{{Key: "$push", Value: "$type"}}}}, BsonBuilder().Push("items", "$item").Push("types", "$type").Build())
57+
assert.Equal(t, bson.D{bson.E{Key: "items", Value: bson.D{{Key: "$push", Value: "$item"}}}, bson.E{Key: "types", Value: bson.D{{Key: "$push", Value: "$type"}}}}, NewBuilder().Push("items", "$item").Push("types", "$type").Build())
5858
})
5959
}
6060

@@ -67,23 +67,23 @@ func Test_accumulatorsBuilder_PushWithoutKey(t *testing.T) {
6767
{
6868
name: "normal",
6969
// { item: "$item", quantity: "$quantity" }
70-
expression: BsonBuilder().AddKeyValues("item", "$item").AddKeyValues("quantity", "$quantity").Build(),
70+
expression: NewBuilder().KeyValue("item", "$item").KeyValue("quantity", "$quantity").Build(),
7171
expected: bson.D{{Key: "$push", Value: bson.D{{Key: "item", Value: "$item"}, {Key: "quantity", Value: "$quantity"}}}},
7272
},
7373
}
7474
for _, tc := range testCases {
7575
t.Run(tc.name, func(t *testing.T) {
76-
assert.Equal(t, tc.expected, BsonBuilder().PushWithoutKey(tc.expression).Build())
76+
assert.Equal(t, tc.expected, NewBuilder().PushWithoutKey(tc.expression).Build())
7777
})
7878
}
7979
}
8080

8181
func Test_accumulatorsBuilder_Avg(t *testing.T) {
8282
t.Run("single operation", func(t *testing.T) {
83-
assert.Equal(t, bson.D{bson.E{Key: "avgAmount", Value: bson.D{{Key: "$avg", Value: "$price"}}}}, BsonBuilder().Avg("avgAmount", "$price").Build())
83+
assert.Equal(t, bson.D{bson.E{Key: "avgAmount", Value: bson.D{{Key: "$avg", Value: "$price"}}}}, NewBuilder().Avg("avgAmount", "$price").Build())
8484
})
8585
t.Run("multiple operations", func(t *testing.T) {
86-
assert.Equal(t, bson.D{bson.E{Key: "avgAmount", Value: bson.D{{Key: "$avg", Value: "$price"}}}, bson.E{Key: "avgFee", Value: bson.D{{Key: "$avg", Value: "$fee"}}}}, BsonBuilder().Avg("avgAmount", "$price").Avg("avgFee", "$fee").Build())
86+
assert.Equal(t, bson.D{bson.E{Key: "avgAmount", Value: bson.D{{Key: "$avg", Value: "$price"}}}, bson.E{Key: "avgFee", Value: bson.D{{Key: "$avg", Value: "$fee"}}}}, NewBuilder().Avg("avgAmount", "$price").Avg("avgFee", "$fee").Build())
8787
})
8888
}
8989

@@ -96,23 +96,23 @@ func Test_accumulatorsBuilder_AvgWithoutKey(t *testing.T) {
9696
{
9797
name: "normal",
9898
// { $multiply: [ "$price", "$quantity" ] }
99-
expression: BsonBuilder().MultiplyWithoutKey("$price", "$quantity").Build(),
99+
expression: NewBuilder().MultiplyWithoutKey("$price", "$quantity").Build(),
100100
expected: bson.D{{Key: "$avg", Value: bson.D{{Key: "$multiply", Value: []any{"$price", "$quantity"}}}}},
101101
},
102102
}
103103
for _, tc := range testCases {
104104
t.Run(tc.name, func(t *testing.T) {
105-
assert.Equal(t, tc.expected, BsonBuilder().AvgWithoutKey(tc.expression).Build())
105+
assert.Equal(t, tc.expected, NewBuilder().AvgWithoutKey(tc.expression).Build())
106106
})
107107
}
108108
}
109109

110110
func Test_accumulatorsBuilder_First(t *testing.T) {
111111
t.Run("single operation", func(t *testing.T) {
112-
assert.Equal(t, bson.D{bson.E{Key: "firstType", Value: bson.D{{Key: "$first", Value: "$type"}}}}, BsonBuilder().First("firstType", "$type").Build())
112+
assert.Equal(t, bson.D{bson.E{Key: "firstType", Value: bson.D{{Key: "$first", Value: "$type"}}}}, NewBuilder().First("firstType", "$type").Build())
113113
})
114114
t.Run("multiple operations", func(t *testing.T) {
115-
assert.Equal(t, bson.D{bson.E{Key: "firstType", Value: bson.D{{Key: "$first", Value: "$type"}}}, bson.E{Key: "firstPrice", Value: bson.D{{Key: "$first", Value: "$price"}}}}, BsonBuilder().First("firstType", "$type").First("firstPrice", "$price").Build())
115+
assert.Equal(t, bson.D{bson.E{Key: "firstType", Value: bson.D{{Key: "$first", Value: "$type"}}}, bson.E{Key: "firstPrice", Value: bson.D{{Key: "$first", Value: "$price"}}}}, NewBuilder().First("firstType", "$type").First("firstPrice", "$price").Build())
116116
})
117117
}
118118

@@ -130,17 +130,17 @@ func Test_accumulatorsBuilder_FirstWithoutKey(t *testing.T) {
130130
}
131131
for _, tc := range testCases {
132132
t.Run(tc.name, func(t *testing.T) {
133-
assert.Equal(t, tc.expected, BsonBuilder().FirstWithoutKey(tc.expression).Build())
133+
assert.Equal(t, tc.expected, NewBuilder().FirstWithoutKey(tc.expression).Build())
134134
})
135135
}
136136
}
137137

138138
func Test_accumulatorsBuilder_Last(t *testing.T) {
139139
t.Run("single operation", func(t *testing.T) {
140-
assert.Equal(t, bson.D{bson.E{Key: "lastType", Value: bson.D{{Key: "$last", Value: "$type"}}}}, BsonBuilder().Last("lastType", "$type").Build())
140+
assert.Equal(t, bson.D{bson.E{Key: "lastType", Value: bson.D{{Key: "$last", Value: "$type"}}}}, NewBuilder().Last("lastType", "$type").Build())
141141
})
142142
t.Run("multiple operations", func(t *testing.T) {
143-
assert.Equal(t, bson.D{bson.E{Key: "lastType", Value: bson.D{{Key: "$last", Value: "$type"}}}, bson.E{Key: "lastPrice", Value: bson.D{{Key: "$last", Value: "$price"}}}}, BsonBuilder().Last("lastType", "$type").Last("lastPrice", "$price").Build())
143+
assert.Equal(t, bson.D{bson.E{Key: "lastType", Value: bson.D{{Key: "$last", Value: "$type"}}}, bson.E{Key: "lastPrice", Value: bson.D{{Key: "$last", Value: "$price"}}}}, NewBuilder().Last("lastType", "$type").Last("lastPrice", "$price").Build())
144144
})
145145
}
146146

@@ -158,17 +158,17 @@ func Test_accumulatorsBuilder_LastWithoutKey(t *testing.T) {
158158
}
159159
for _, tc := range testCases {
160160
t.Run(tc.name, func(t *testing.T) {
161-
assert.Equal(t, tc.expected, BsonBuilder().LastWithoutKey(tc.expression).Build())
161+
assert.Equal(t, tc.expected, NewBuilder().LastWithoutKey(tc.expression).Build())
162162
})
163163
}
164164
}
165165

166166
func Test_accumulatorsBuilder_Min(t *testing.T) {
167167
t.Run("single operation", func(t *testing.T) {
168-
assert.Equal(t, bson.D{bson.E{Key: "minPrice", Value: bson.D{{Key: "$min", Value: "$price"}}}}, BsonBuilder().Min("minPrice", "$price").Build())
168+
assert.Equal(t, bson.D{bson.E{Key: "minPrice", Value: bson.D{{Key: "$min", Value: "$price"}}}}, NewBuilder().Min("minPrice", "$price").Build())
169169
})
170170
t.Run("multiple operations", func(t *testing.T) {
171-
assert.Equal(t, bson.D{bson.E{Key: "minPrice", Value: bson.D{{Key: "$min", Value: "$price"}}}, bson.E{Key: "minFee", Value: bson.D{{Key: "$min", Value: "$fee"}}}}, BsonBuilder().Min("minPrice", "$price").Min("minFee", "$fee").Build())
171+
assert.Equal(t, bson.D{bson.E{Key: "minPrice", Value: bson.D{{Key: "$min", Value: "$price"}}}, bson.E{Key: "minFee", Value: bson.D{{Key: "$min", Value: "$fee"}}}}, NewBuilder().Min("minPrice", "$price").Min("minFee", "$fee").Build())
172172
})
173173
}
174174
func Test_accumulatorsBuilder_MinWithoutKey(t *testing.T) {
@@ -185,17 +185,17 @@ func Test_accumulatorsBuilder_MinWithoutKey(t *testing.T) {
185185
}
186186
for _, tc := range testCases {
187187
t.Run(tc.name, func(t *testing.T) {
188-
assert.Equal(t, tc.expected, BsonBuilder().MinWithoutKey(tc.expression).Build())
188+
assert.Equal(t, tc.expected, NewBuilder().MinWithoutKey(tc.expression).Build())
189189
})
190190
}
191191
}
192192

193193
func Test_accumulatorsBuilder_Max(t *testing.T) {
194194
t.Run("single operation", func(t *testing.T) {
195-
assert.Equal(t, bson.D{bson.E{Key: "maxPrice", Value: bson.D{{Key: "$max", Value: "$price"}}}}, BsonBuilder().Max("maxPrice", "$price").Build())
195+
assert.Equal(t, bson.D{bson.E{Key: "maxPrice", Value: bson.D{{Key: "$max", Value: "$price"}}}}, NewBuilder().Max("maxPrice", "$price").Build())
196196
})
197197
t.Run("multiple operations", func(t *testing.T) {
198-
assert.Equal(t, bson.D{bson.E{Key: "maxPrice", Value: bson.D{{Key: "$max", Value: "$price"}}}, bson.E{Key: "maxFee", Value: bson.D{{Key: "$max", Value: "$fee"}}}}, BsonBuilder().Max("maxPrice", "$price").Max("maxFee", "$fee").Build())
198+
assert.Equal(t, bson.D{bson.E{Key: "maxPrice", Value: bson.D{{Key: "$max", Value: "$price"}}}, bson.E{Key: "maxFee", Value: bson.D{{Key: "$max", Value: "$fee"}}}}, NewBuilder().Max("maxPrice", "$price").Max("maxFee", "$fee").Build())
199199
})
200200
}
201201

@@ -213,7 +213,7 @@ func Test_accumulatorsBuilder_MaxWithoutKey(t *testing.T) {
213213
}
214214
for _, tc := range testCases {
215215
t.Run(tc.name, func(t *testing.T) {
216-
assert.Equal(t, tc.expected, BsonBuilder().MaxWithoutKey(tc.expression).Build())
216+
assert.Equal(t, tc.expected, NewBuilder().MaxWithoutKey(tc.expression).Build())
217217
})
218218
}
219219
}

builder/aggregation/aggregation_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"go.mongodb.org/mongo-driver/bson"
1919
)
2020

21-
func BsonBuilder() *Builder {
21+
func NewBuilder() *Builder {
2222
b := &Builder{d: bson.D{}}
2323

2424
b.arithmeticBuilder = arithmeticBuilder{parent: b}
@@ -50,7 +50,7 @@ func (b *Builder) Build() bson.D {
5050
return b.d
5151
}
5252

53-
func (b *Builder) AddKeyValues(key string, value any) *Builder {
53+
func (b *Builder) KeyValue(key string, value any) *Builder {
5454
b.d = append(b.d, bson.E{Key: key, Value: value})
5555
return b
5656
}

builder/aggregation/aggregation_builder_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"go.mongodb.org/mongo-driver/bson"
2222
)
2323

24-
func TestBuilder_AddKeyValues(t *testing.T) {
25-
assert.Equal(t, bson.D{bson.E{Key: "name", Value: "chenmingyong"}}, BsonBuilder().AddKeyValues("name", "chenmingyong").Build())
24+
func TestBuilder_KeyValue(t *testing.T) {
25+
assert.Equal(t, bson.D{bson.E{Key: "name", Value: "chenmingyong"}}, NewBuilder().KeyValue("name", "chenmingyong").Build())
2626
}
2727

2828
func TestBuilder_tryMergeValue(t *testing.T) {
29-
assert.True(t, BsonBuilder().Push("items", "$item").tryMergeValue("items", bson.E{Key: "$avg", Value: "$items"}))
29+
assert.True(t, NewBuilder().Push("items", "$item").tryMergeValue("items", bson.E{Key: "$avg", Value: "$items"}))
3030
}

builder/aggregation/aggregation_stage_builder_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestStageBuilder_Bucket(t *testing.T) {
155155
groupBy: "$year_born",
156156
opt: &BucketOptions{
157157
DefaultKey: nil,
158-
Output: BsonBuilder().Sum("count", 1).Build(),
158+
Output: NewBuilder().Sum("count", 1).Build(),
159159
},
160160
boundaries: []any{1840, 1850, 1860, 1870, 1880},
161161
want: mongo.Pipeline{
@@ -171,7 +171,7 @@ func TestStageBuilder_Bucket(t *testing.T) {
171171
groupBy: "$year_born",
172172
opt: &BucketOptions{
173173
DefaultKey: "Other",
174-
Output: BsonBuilder().Sum("count", 1).Build(),
174+
Output: NewBuilder().Sum("count", 1).Build(),
175175
},
176176
boundaries: nil,
177177
want: mongo.Pipeline{
@@ -188,7 +188,7 @@ func TestStageBuilder_Bucket(t *testing.T) {
188188
groupBy: "$year_born",
189189
opt: &BucketOptions{
190190
DefaultKey: "Other",
191-
Output: BsonBuilder().Sum("count", 1).Push("artists", BsonBuilder().Concat("name", "$first_name", " ", "$last_name").AddKeyValues("year_born", "$year_born").Build()).Build(),
191+
Output: NewBuilder().Sum("count", 1).Push("artists", NewBuilder().Concat("name", "$first_name", " ", "$last_name").KeyValue("year_born", "$year_born").Build()).Build(),
192192
},
193193
boundaries: []any{1840, 1850, 1860, 1870, 1880},
194194
want: mongo.Pipeline{
@@ -255,7 +255,7 @@ func TestStageBuilder_BucketAuto(t *testing.T) {
255255
name: "granularity is empty",
256256
groupBy: "$price",
257257
opt: &BucketAutoOptions{
258-
Output: BsonBuilder().Sum("count", 1).Build(),
258+
Output: NewBuilder().Sum("count", 1).Build(),
259259
},
260260
buckets: 4,
261261
want: mongo.Pipeline{
@@ -270,7 +270,7 @@ func TestStageBuilder_BucketAuto(t *testing.T) {
270270
name: "normal",
271271
groupBy: "$price",
272272
opt: &BucketAutoOptions{
273-
Output: BsonBuilder().Sum("count", 1).Build(),
273+
Output: NewBuilder().Sum("count", 1).Build(),
274274
Granularity: "R5",
275275
},
276276
buckets: 4,
@@ -304,7 +304,7 @@ func TestStageBuilder_Match(t *testing.T) {
304304
},
305305
{
306306
name: "expression is not nil",
307-
expression: BsonBuilder().AddKeyValues("author", "dave").Build(),
307+
expression: NewBuilder().KeyValue("author", "dave").Build(),
308308
want: mongo.Pipeline{bson.D{bson.E{Key: "$match", Value: bson.D{bson.E{Key: "author", Value: "dave"}}}}},
309309
},
310310
}
@@ -331,7 +331,7 @@ func TestStageBuilder_Group(t *testing.T) {
331331
{
332332
name: "id is nil",
333333
id: nil,
334-
accumulators: BsonBuilder().
334+
accumulators: NewBuilder().
335335
Sum("totalSaleAmount", bsonx.D("$multiply", []any{"$price", "$quantity"})).
336336
Avg("averageQuantity", "$quantity").
337337
Sum("count", 1).Build(),
@@ -356,7 +356,7 @@ func TestStageBuilder_Group(t *testing.T) {
356356
{
357357
name: "id and accumulators are not nil",
358358
id: bsonx.D("x", "$x"),
359-
accumulators: BsonBuilder().
359+
accumulators: NewBuilder().
360360
Sum("totalSaleAmount", bsonx.D("$multiply", []any{"$price", "$quantity"})).
361361
Avg("averageQuantity", "$quantity").
362362
Sum("count", 1).Build(),
@@ -518,7 +518,7 @@ func TestStageBuilder_ReplaceWith(t *testing.T) {
518518
},
519519
//{
520520
// name: "replacementDocument of bson.D",
521-
// replacementDocument: BsonBuilder().ArrayToObject("$items").Build(),
521+
// replacementDocument: NewBuilder().ArrayToObject("$items").Build(),
522522
// want: mongo.Pipeline{bson.D{bson.E{Key: "$replaceWith", Value: bson.D{bson.E{Key: "$arrayToObject", Value: "$items"}}}}},
523523
//},
524524
}
@@ -578,9 +578,9 @@ func TestStageBuilder_Facet(t *testing.T) {
578578
// value: bsonx.NewD().
579579
// Add("categorizedByTags", StageBsonBuilder().Unwind("$tags", nil).SortByCount("$tags").Build()).
580580
// Add("categorizedByPrice", StageBsonBuilder().Match(
581-
// BsonBuilder().AddKeyValues("price", BsonBuilder().AddKeyValues("$exists", 1).Build()).Build()).Bucket("$price", []any{0, 150, 200, 300, 400}, &BucketOptions{
581+
// NewBuilder().KeyValue("price", NewBuilder().KeyValue("$exists", 1).Build()).Build()).Bucket("$price", []any{0, 150, 200, 300, 400}, &BucketOptions{
582582
// DefaultKey: "Other",
583-
// Output: BsonBuilder().AddKeyValues("count", BsonBuilder().Sum(1).Build()).AddKeyValues("titles", BsonBuilder().Push("$title").Build()).Build(),
583+
// Output: NewBuilder().KeyValue("count", NewBuilder().Sum(1).Build()).KeyValue("titles", NewBuilder().Push("$title").Build()).Build(),
584584
// }).Build()).
585585
// Add("categorizedByYears(Auto)", StageBsonBuilder().BucketAuto("$year", 4, nil).Build()).Build(),
586586
// want: mongo.Pipeline{bson.D{bson.E{Key: "$facet", Value: bson.D{
@@ -636,7 +636,7 @@ func TestStageBuilder_SortByCount(t *testing.T) {
636636
// { $sortByCount: { lname: "$employee.last", fname: "$employee.first" } }
637637
{
638638
name: "expression of bson.D",
639-
expression: BsonBuilder().AddKeyValues("lname", "$employee.last").AddKeyValues("fname", "$employee.first").Build(),
639+
expression: NewBuilder().KeyValue("lname", "$employee.last").KeyValue("fname", "$employee.first").Build(),
640640
want: mongo.Pipeline{bson.D{bson.E{Key: "$sortByCount", Value: bson.D{
641641
bson.E{Key: "lname", Value: "$employee.last"},
642642
bson.E{Key: "fname", Value: "$employee.first"},

builder/aggregation/arithmetic_builder_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
func Test_arithmeticBuilder_Add(t *testing.T) {
2525
t.Run("test add", func(t *testing.T) {
2626
assert.Equal(t, bson.D{bson.E{Key: "total", Value: bson.D{bson.E{Key: "$add", Value: []any{1, 2, 3, "$a", "$b", "$c"}}}}},
27-
BsonBuilder().Add("total", 1, 2, 3, "$a", "$b", "$c").Build(),
27+
NewBuilder().Add("total", 1, 2, 3, "$a", "$b", "$c").Build(),
2828
)
2929
})
3030
}
@@ -58,15 +58,15 @@ func Test_arithmeticBuilder_AddWithoutKey(t *testing.T) {
5858
}
5959
for _, tc := range testCases {
6060
t.Run(tc.name, func(t *testing.T) {
61-
assert.Equal(t, tc.expected, BsonBuilder().AddWithoutKey(tc.expressions...).Build())
61+
assert.Equal(t, tc.expected, NewBuilder().AddWithoutKey(tc.expressions...).Build())
6262
})
6363
}
6464
}
6565

6666
func Test_arithmeticBuilder_Multiply(t *testing.T) {
6767
t.Run("test multiply", func(t *testing.T) {
6868
assert.Equal(t, bson.D{bson.E{Key: "total", Value: bson.D{bson.E{Key: "$multiply", Value: []any{1, 2, 3, "$a", "$b", "$c"}}}}},
69-
BsonBuilder().Multiply("total", 1, 2, 3, "$a", "$b", "$c").Build(),
69+
NewBuilder().Multiply("total", 1, 2, 3, "$a", "$b", "$c").Build(),
7070
)
7171
})
7272
}
@@ -100,15 +100,15 @@ func Test_arithmeticBuilder_MultiplyWithoutKey(t *testing.T) {
100100
}
101101
for _, tc := range testCases {
102102
t.Run(tc.name, func(t *testing.T) {
103-
assert.Equal(t, tc.expected, BsonBuilder().MultiplyWithoutKey(tc.expressions...).Build())
103+
assert.Equal(t, tc.expected, NewBuilder().MultiplyWithoutKey(tc.expressions...).Build())
104104
})
105105
}
106106
}
107107

108108
func Test_arithmeticBuilder_Subtract(t *testing.T) {
109109
t.Run("test subtract", func(t *testing.T) {
110110
assert.Equal(t, bson.D{bson.E{Key: "dateDifference", Value: bson.D{bson.E{Key: "$subtract", Value: []any{"$date", 5 * 60 * 1000}}}}},
111-
BsonBuilder().Subtract("dateDifference", []any{"$date", 5 * 60 * 1000}...).Build(),
111+
NewBuilder().Subtract("dateDifference", []any{"$date", 5 * 60 * 1000}...).Build(),
112112
)
113113
})
114114

@@ -128,15 +128,15 @@ func Test_arithmeticBuilder_SubtractWithoutKey(t *testing.T) {
128128
}
129129
for _, tc := range testCases {
130130
t.Run(tc.name, func(t *testing.T) {
131-
assert.Equal(t, tc.expected, BsonBuilder().SubtractWithoutKey(tc.expressions...).Build())
131+
assert.Equal(t, tc.expected, NewBuilder().SubtractWithoutKey(tc.expressions...).Build())
132132
})
133133
}
134134
}
135135

136136
func Test_arithmeticBuilder_Divide(t *testing.T) {
137137
t.Run("test divide", func(t *testing.T) {
138138
assert.Equal(t, bson.D{bson.E{Key: "total", Value: bson.D{bson.E{Key: "$divide", Value: []any{1, 2, 3, "$a", "$b", "$c"}}}}},
139-
BsonBuilder().Divide("total", 1, 2, 3, "$a", "$b", "$c").Build(),
139+
NewBuilder().Divide("total", 1, 2, 3, "$a", "$b", "$c").Build(),
140140
)
141141
})
142142
}
@@ -154,15 +154,15 @@ func Test_arithmeticBuilder_DivideWithoutKey(t *testing.T) {
154154
}
155155
for _, tc := range testCases {
156156
t.Run(tc.name, func(t *testing.T) {
157-
assert.Equal(t, tc.expected, BsonBuilder().DivideWithoutKey(tc.expressions...).Build())
157+
assert.Equal(t, tc.expected, NewBuilder().DivideWithoutKey(tc.expressions...).Build())
158158
})
159159
}
160160
}
161161

162162
func Test_arithmeticBuilder_Mod(t *testing.T) {
163163
t.Run("test mod", func(t *testing.T) {
164164
assert.Equal(t, bson.D{bson.E{Key: "total", Value: bson.D{bson.E{Key: "$mod", Value: []any{1, 2, 3, "$a", "$b", "$c"}}}}},
165-
BsonBuilder().Mod("total", 1, 2, 3, "$a", "$b", "$c").Build(),
165+
NewBuilder().Mod("total", 1, 2, 3, "$a", "$b", "$c").Build(),
166166
)
167167
})
168168
}
@@ -180,7 +180,7 @@ func Test_arithmeticBuilder_ModWithoutKey(t *testing.T) {
180180
}
181181
for _, tc := range testCases {
182182
t.Run(tc.name, func(t *testing.T) {
183-
assert.Equal(t, tc.expected, BsonBuilder().ModWithoutKey(tc.expressions...).Build())
183+
assert.Equal(t, tc.expected, NewBuilder().ModWithoutKey(tc.expressions...).Build())
184184
})
185185
}
186186
}

0 commit comments

Comments
 (0)