@@ -23,10 +23,10 @@ import (
2323
2424func 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
5252func 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
8181func 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
110110func 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
138138func 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
166166func 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}
174174func 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
193193func 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}
0 commit comments