@@ -20,22 +20,20 @@ import (
2020 "context"
2121 "testing"
2222
23- "go.mongodb.org/mongo-driver/bson/primitive"
24-
23+ "github.com/chenmingyong0423/go-mongox/v2/bsonx"
2524 "github.com/stretchr/testify/require"
2625
27- "github.com/chenmingyong0423/go-mongox/bsonx"
28-
29- "github.com/chenmingyong0423/go-mongox/builder/aggregation"
30- "github.com/chenmingyong0423/go-mongox/builder/query"
26+ "github.com/chenmingyong0423/go-mongox/v2/builder/aggregation"
27+ "github.com/chenmingyong0423/go-mongox/v2/builder/query"
3128
32- "go.mongodb.org/mongo-driver/mongo"
33- "go.mongodb.org/mongo-driver/mongo/options"
34- "go.mongodb.org/mongo-driver/mongo/readpref"
29+ "go.mongodb.org/mongo-driver/v2/bson"
30+ "go.mongodb.org/mongo-driver/v2/mongo"
31+ "go.mongodb.org/mongo-driver/v2/mongo/options"
32+ "go.mongodb.org/mongo-driver/v2/mongo/readpref"
3533)
3634
3735func getCollection (t * testing.T ) * mongo.Collection {
38- client , err := mongo .Connect (context . Background (), options .Client ().ApplyURI ("mongodb://localhost:27017" ).SetAuth (options.Credential {
36+ client , err := mongo .Connect (options .Client ().ApplyURI ("mongodb://localhost:27017" ).SetAuth (options.Credential {
3937 Username : "test" ,
4038 Password : "test" ,
4139 AuthSource : "db-test" ,
@@ -64,7 +62,7 @@ func TestAggregator_e2e_Aggregation(t *testing.T) {
6462 after func (ctx context.Context , t * testing.T )
6563
6664 pipeline any
67- aggregationOptions []* options.AggregateOptions
65+ aggregationOptions []options.Lister [options. AggregateOptions ]
6866
6967 ctx context.Context
7068 want []* TestUser
@@ -190,7 +188,7 @@ func TestAggregator_e2e_Aggregation(t *testing.T) {
190188 require .Equal (t , int64 (2 ), deleteResult .DeletedCount )
191189 },
192190 pipeline : aggregation .NewStageBuilder ().Sort (bsonx .M ("age" , 1 )).Build (),
193- aggregationOptions : []* options.AggregateOptions {
191+ aggregationOptions : []options.Lister [options. AggregateOptions ] {
194192 options .Aggregate ().SetCollation (& options.Collation {Locale : "en" , Strength : 2 }),
195193 },
196194 want : []* TestUser {
@@ -214,7 +212,7 @@ func TestAggregator_e2e_Aggregation(t *testing.T) {
214212 if err == nil {
215213 require .Equal (t , len (tc .want ), len (testUsers ))
216214 for _ , tu := range testUsers {
217- var zero primitive .ObjectID
215+ var zero bson .ObjectID
218216 tu .ID = zero
219217 }
220218 require .ElementsMatch (t , tc .want , testUsers )
@@ -239,7 +237,7 @@ func TestAggregator_e2e_AggregateWithParse(t *testing.T) {
239237 before func (ctx context.Context , t * testing.T )
240238 after func (ctx context.Context , t * testing.T )
241239 pipeline any
242- aggregationOptions * options.AggregateOptions
240+ aggregationOptions [] options.Lister [options. AggregateOptions ]
243241 ctx context.Context
244242 result any
245243 want []* User
@@ -301,9 +299,11 @@ func TestAggregator_e2e_AggregateWithParse(t *testing.T) {
301299 {Id : "1" , Name : "cmy" , Age : 24 , IsProgrammer : true },
302300 {Id : "2" , Name : "gopher" , Age : 20 , IsProgrammer : true },
303301 },
304- aggregationOptions : options .Aggregate ().SetCollation (& options.Collation {Locale : "en" , Strength : 2 }),
305- ctx : context .Background (),
306- wantErr : require .NoError ,
302+ aggregationOptions : []options.Lister [options.AggregateOptions ]{
303+ options .Aggregate ().SetCollation (& options.Collation {Locale : "en" , Strength : 2 }),
304+ },
305+ ctx : context .Background (),
306+ wantErr : require .NoError ,
307307 },
308308 {
309309 name : "got error from cursor" ,
@@ -320,18 +320,20 @@ func TestAggregator_e2e_AggregateWithParse(t *testing.T) {
320320 require .NoError (t , err )
321321 require .Equal (t , int64 (2 ), deleteResult .DeletedCount )
322322 },
323- pipeline : aggregation .NewStageBuilder ().Set (bsonx .M ("is_programmer" , true )).Sort (bsonx .M ("name" , 1 )).Build (),
324- result : []string {},
325- want : []* User {},
326- aggregationOptions : options .Aggregate ().SetCollation (& options.Collation {Locale : "en" , Strength : 2 }),
327- ctx : context .Background (),
328- wantErr : require .Error ,
323+ pipeline : aggregation .NewStageBuilder ().Set (bsonx .M ("is_programmer" , true )).Sort (bsonx .M ("name" , 1 )).Build (),
324+ result : []string {},
325+ want : []* User {},
326+ aggregationOptions : []options.Lister [options.AggregateOptions ]{
327+ options .Aggregate ().SetCollation (& options.Collation {Locale : "en" , Strength : 2 }),
328+ },
329+ ctx : context .Background (),
330+ wantErr : require .Error ,
329331 },
330332 }
331333 for _ , tc := range testCases {
332334 t .Run (tc .name , func (t * testing.T ) {
333335 tc .before (tc .ctx , t )
334- err := aggregator .Pipeline (tc .pipeline ).AggregateWithParse (tc .ctx , & tc .result , tc .aggregationOptions )
336+ err := aggregator .Pipeline (tc .pipeline ).AggregateWithParse (tc .ctx , & tc .result , tc .aggregationOptions ... )
335337 tc .after (tc .ctx , t )
336338 tc .wantErr (t , err )
337339 if err == nil {
0 commit comments