@@ -20,7 +20,7 @@ import (
2020 "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
2121)
2222
23- func TestNewSessionWithID (t * testing.T ) {
23+ func TestNewSessionWithLSID (t * testing.T ) {
2424 mt := mtest .New (t )
2525
2626 mt .Run ("can be used to pass a specific session ID to CRUD commands" , func (mt * mtest.T ) {
@@ -32,7 +32,7 @@ func TestNewSessionWithID(t *testing.T) {
3232 AppendBinary ("id" , 4 , []byte {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 }).
3333 Build ())
3434
35- sess := mongo .NewSessionWithID (mt .Client , sessionID )
35+ sess := mongo .NewSessionWithLSID (mt .Client , sessionID )
3636
3737 ctx := mongo .NewSessionContext (context .Background (), sess )
3838 _ , err := mt .Coll .InsertOne (ctx , bson.D {{"foo" , "bar" }})
@@ -52,22 +52,47 @@ func TestNewSessionWithID(t *testing.T) {
5252 mt .Parallel ()
5353
5454 sessionID := bson .Raw (bsoncore .NewDocumentBuilder ().
55- AppendBinary ("id" , 4 , []byte {}).
55+ AppendBinary ("id" , 4 , []byte {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }).
5656 Build ())
57- sess := mongo .NewSessionWithID (mt .Client , sessionID )
57+ sess := mongo .NewSessionWithLSID (mt .Client , sessionID )
5858
5959 // Use a defer-recover block to catch the expected panic and assert that
6060 // the recovered error is not nil.
6161 defer func () {
6262 err := recover ()
63- assert .NotNil (mt , err , "expected panic error to not be nil " )
63+ assert .NotNil (mt , err , "expected EndSession to panic " )
6464 }()
6565
66+ // Expect this call to panic.
6667 sess .EndSession (context .Background ())
6768
6869 // We expect that calling EndSession on a Session returned by
69- // NewSessionWithID panics. This code will only be reached if EndSession
70+ // NewSessionWithLSID panics. This code will only be reached if EndSession
7071 // doesn't panic.
7172 t .Errorf ("expected EndSession to panic" )
7273 })
74+
75+ mt .Run ("ClientSession.SetServer panics" , func (mt * mtest.T ) {
76+ mt .Parallel ()
77+
78+ sessionID := bson .Raw (bsoncore .NewDocumentBuilder ().
79+ AppendBinary ("id" , 4 , []byte {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }).
80+ Build ())
81+ sess := mongo .NewSessionWithLSID (mt .Client , sessionID )
82+
83+ // Use a defer-recover block to catch the expected panic and assert that
84+ // the recovered error is not nil.
85+ defer func () {
86+ err := recover ()
87+ assert .NotNil (mt , err , "expected ClientSession.SetServer to panic" )
88+ }()
89+
90+ // Expect this call to panic.
91+ sess .ClientSession ().SetServer ()
92+
93+ // We expect that calling ClientSession.SetServer on a Session returned
94+ // by NewSessionWithLSID panics. This code will only be reached if
95+ // ClientSession.SetServer doesn't panic.
96+ t .Errorf ("expected ClientSession.SetServer to panic" )
97+ })
7398}
0 commit comments