@@ -1025,16 +1025,21 @@ func TestCollection_Aggregate(t *testing.T) {
1025
1025
}
1026
1026
}
1027
1027
1028
- func TestCollection_Aggregate_withOptions (t * testing.T ) {
1029
- if testing .Short () {
1030
- t .Skip ("skipping integration test in short mode" )
1031
- }
1032
-
1033
- t .Parallel ()
1034
-
1028
+ func testAggregateWithOptions (t * testing.T , createIndex bool , option option.AggregateOptioner ) error {
1035
1029
coll := createTestCollection (t , nil , nil )
1036
1030
initCollection (t , coll )
1037
1031
1032
+ if createIndex {
1033
+ indexView := coll .Indexes ()
1034
+ _ , err := indexView .CreateOne (context .Background (), IndexModel {
1035
+ Keys : bson .NewDocument (bson .EC .Int32 ("x" , 1 )),
1036
+ })
1037
+
1038
+ if err != nil {
1039
+ return err
1040
+ }
1041
+ }
1042
+
1038
1043
pipeline := bson .NewArray (
1039
1044
bson .VC .DocumentFromElements (
1040
1045
bson .EC .SubDocumentFromElements (
@@ -1059,24 +1064,65 @@ func TestCollection_Aggregate_withOptions(t *testing.T) {
1059
1064
),
1060
1065
))
1061
1066
1062
- cursor , err := coll .Aggregate (context .Background (), pipeline , Opt .AllowDiskUse (true ))
1063
- require .Nil (t , err )
1067
+ cursor , err := coll .Aggregate (context .Background (), pipeline , option )
1068
+ if err != nil {
1069
+ return err
1070
+ }
1064
1071
1065
1072
for i := 2 ; i < 5 ; i ++ {
1066
1073
var doc = bson .NewDocument ()
1067
1074
cursor .Next (context .Background ())
1068
1075
err = cursor .Decode (doc )
1069
- require .NoError (t , err )
1076
+ if err != nil {
1077
+ return err
1078
+ }
1079
+
1080
+ if doc .Len () != 1 {
1081
+ return fmt .Errorf ("got doc len %d, expected 1" , doc .Len ())
1082
+ }
1070
1083
1071
- require .Equal (t , doc .Len (), 1 )
1072
1084
num , err := doc .LookupErr ("x" )
1073
- require .NoError (t , err )
1085
+ if err != nil {
1086
+ return err
1087
+ }
1088
+
1074
1089
if num .Type () != bson .TypeInt32 {
1075
- t .Errorf ("Incorrect type for x. Got %s, but wanted Int32" , num .Type ())
1076
- t .FailNow ()
1090
+ return fmt .Errorf ("incorrect type for x. got %s, wanted Int32" , num .Type ())
1077
1091
}
1078
- require .Equal (t , int (num .Int32 ()), i )
1092
+
1093
+ if int (num .Int32 ()) != i {
1094
+ return fmt .Errorf ("unexpected value returned. got %d, expected %d" , int (num .Int32 ()), i )
1095
+ }
1096
+ }
1097
+
1098
+ return nil
1099
+ }
1100
+
1101
+ func TestCollection_Aggregate_IndexHint (t * testing.T ) {
1102
+ skipIfBelow36 (t )
1103
+
1104
+ if testing .Short () {
1105
+ t .Skip ("skipping integration test in short mode" )
1106
+ }
1107
+
1108
+ t .Parallel ()
1109
+
1110
+ hint , err := Opt .Hint (bson .NewDocument (bson .EC .Int32 ("x" , 1 )))
1111
+ require .NoError (t , err )
1112
+
1113
+ err = testAggregateWithOptions (t , true , hint )
1114
+ require .NoError (t , err )
1115
+ }
1116
+
1117
+ func TestCollection_Aggregate_withOptions (t * testing.T ) {
1118
+ if testing .Short () {
1119
+ t .Skip ("skipping integration test in short mode" )
1079
1120
}
1121
+
1122
+ t .Parallel ()
1123
+
1124
+ err := testAggregateWithOptions (t , false , Opt .AllowDiskUse (true ))
1125
+ require .NoError (t , err )
1080
1126
}
1081
1127
1082
1128
func TestCollection_Count (t * testing.T ) {
0 commit comments