Skip to content

Commit d762b10

Browse files
committed
test: assert clientSession is not nil
1 parent d52c9e1 commit d762b10

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

mongo/integration/unified_spec_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,19 @@ func executeGridFSOperation(mt *mtest.T, bucket *gridfs.Bucket, op *operation) e
447447
}
448448

449449
func executeTestRunnerOperation(mt *mtest.T, testCase *testCase, op *operation, sess mongo.Session) error {
450+
if sess == nil {
451+
return fmt.Errorf("received unexpected nil session")
452+
}
453+
450454
var clientSession *session.Client
451-
if sess != nil {
452-
xsess, ok := sess.(mongo.XSession)
453-
if !ok {
454-
return fmt.Errorf("expected session type %T to implement mongo.XSession", sess)
455-
}
456-
clientSession = xsess.ClientSession()
455+
xsess, ok := sess.(mongo.XSession)
456+
if !ok {
457+
return fmt.Errorf("expected session type %T to implement mongo.XSession", sess)
457458
}
458459

460+
clientSession = xsess.ClientSession()
461+
assert.NotNil(mt, clientSession, "expected valid session, got nil")
462+
459463
switch op.Name {
460464
case "targetedFailPoint":
461465
fpDoc := op.Arguments.Lookup("failPoint")
@@ -480,23 +484,29 @@ func executeTestRunnerOperation(mt *mtest.T, testCase *testCase, op *operation,
480484
mt.TrackFailPoint(fp.ConfigureFailPoint)
481485
case "configureFailPoint":
482486
fp, err := op.Arguments.LookupErr("failPoint")
483-
assert.Nil(mt, err, "failPoint not found in arguments")
487+
if err != nil {
488+
return fmt.Errorf("unable to find 'failPoint' in arguments: %v", err)
489+
}
484490
mt.SetFailPointFromDocument(fp.Document())
485491
case "assertSessionTransactionState":
486492
stateVal, err := op.Arguments.LookupErr("state")
487-
assert.Nil(mt, err, "state not found in arguments")
493+
if err != nil {
494+
return fmt.Errorf("unable to find 'state' in arguments: %v", err)
495+
}
488496
expectedState, ok := stateVal.StringValueOK()
489-
assert.True(mt, ok, "state argument is not a string")
497+
if !ok {
498+
return fmt.Errorf("expected 'state' argument to be string")
499+
}
490500

491-
assert.NotNil(mt, clientSession, "expected valid session, got nil")
492501
actualState := clientSession.TransactionState.String()
493502

494503
// actualState should match expectedState, but "in progress" is the same as
495504
// "in_progress".
496505
stateMatch := actualState == expectedState ||
497506
actualState == "in progress" && expectedState == "in_progress"
498-
assert.True(mt, stateMatch, "expected transaction state %v, got %v",
499-
expectedState, actualState)
507+
if !stateMatch {
508+
return fmt.Errorf("expected transaction state %v, got %v", expectedState, actualState)
509+
}
500510
case "assertSessionPinned":
501511
if clientSession.PinnedServer == nil {
502512
return errors.New("expected pinned server, got nil")

0 commit comments

Comments
 (0)