File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,10 @@ func (c *cursor) ID() int64 {
79
79
}
80
80
81
81
func (c * cursor ) Next (ctx context.Context ) bool {
82
+ if ctx == nil {
83
+ ctx = context .Background ()
84
+ }
85
+
82
86
c .current ++
83
87
if c .current < c .batch .Len () {
84
88
return true
Original file line number Diff line number Diff line change
1
+ package topology
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/mongodb/mongo-go-driver/bson"
7
+ "github.com/stretchr/testify/assert"
8
+ )
9
+
10
+ func TestCursorNextDoesNotPanicIfContextisNil (t * testing.T ) {
11
+ // all collection/cursor iterators should take contexts, but
12
+ // permit passing nils for contexts, which should not
13
+ // panic.
14
+ //
15
+ // While more through testing might be ideal this check
16
+ // prevents a regression of GODRIVER-298
17
+
18
+ c := cursor {batch : bson .NewArray (bson .VC .String ("a" ), bson .VC .String ("b" ))}
19
+
20
+ var iterNext bool
21
+ assert .NotPanics (t , func () {
22
+ iterNext = c .Next (nil )
23
+ })
24
+ assert .True (t , iterNext )
25
+ }
You can’t perform that action at this time.
0 commit comments