@@ -16,11 +16,11 @@ var testTime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
1616func  TestBasicSessionStore (t  * testing.T ) {
1717	// Set up a new DB. 
1818	clock  :=  clock .NewTestClock (testTime )
19- 	db ,  err   :=  NewDB ( t . TempDir (),  "test.db" , clock )
20- 	 require . NoError ( t ,  err ) 
21- 	t . Cleanup ( func () { 
22- 		 _   =  db .Close ( )
23- 	} )
19+ 	db   :=  NewTestDB ( t , clock )
20+ 
21+ 	// Try fetch a session that doesn't exist yet. 
22+ 	_ ,  err   : =  db .GetSessionByID ( ID { 1 ,  3 ,  4 ,  4 } )
23+ 	require . ErrorIs ( t ,  err ,  ErrSessionNotFound )
2424
2525	// Reserve a session. This should succeed. 
2626	s1 , err  :=  reserveSession (db , "session 1" )
@@ -183,7 +183,7 @@ func TestBasicSessionStore(t *testing.T) {
183183	require .Empty (t , sessions )
184184
185185	_ , err  =  db .GetGroupID (s4 .ID )
186- 	require .ErrorContains (t , err , "no index entry" )
186+ 	require .ErrorIs (t , err , ErrUnknownGroup )
187187
188188	// Only session 1 should remain in this group. 
189189	sessIDs , err  =  db .GetSessionIDs (s4 .GroupID )
@@ -197,11 +197,7 @@ func TestLinkingSessions(t *testing.T) {
197197
198198	// Set up a new DB. 
199199	clock  :=  clock .NewTestClock (testTime )
200- 	db , err  :=  NewDB (t .TempDir (), "test.db" , clock )
201- 	require .NoError (t , err )
202- 	t .Cleanup (func () {
203- 		_  =  db .Close ()
204- 	})
200+ 	db  :=  NewTestDB (t , clock )
205201
206202	groupID , err  :=  IDFromBytes ([]byte {1 , 2 , 3 , 4 })
207203	require .NoError (t , err )
@@ -211,7 +207,7 @@ func TestLinkingSessions(t *testing.T) {
211207	_ , err  =  reserveSession (
212208		db , "session 2" , withLinkedGroupID (& groupID ),
213209	)
214- 	require .ErrorContains (t , err , "unknown linked session" )
210+ 	require .ErrorIs (t , err , ErrUnknownGroup )
215211
216212	// Create a new session with no previous link. 
217213	s1  :=  createSession (t , db , "session 1" )
@@ -220,7 +216,7 @@ func TestLinkingSessions(t *testing.T) {
220216	// session. This should fail due to the first session still being 
221217	// active. 
222218	_ , err  =  reserveSession (db , "session 2" , withLinkedGroupID (& s1 .GroupID ))
223- 	require .ErrorContains (t , err , "is still active" )
219+ 	require .ErrorIs (t , err , ErrSessionsInGroupStillActive )
224220
225221	// Revoke the first session. 
226222	require .NoError (t , db .ShiftState (s1 .ID , StateRevoked ))
@@ -238,11 +234,7 @@ func TestLinkedSessions(t *testing.T) {
238234
239235	// Set up a new DB. 
240236	clock  :=  clock .NewTestClock (testTime )
241- 	db , err  :=  NewDB (t .TempDir (), "test.db" , clock )
242- 	require .NoError (t , err )
243- 	t .Cleanup (func () {
244- 		_  =  db .Close ()
245- 	})
237+ 	db  :=  NewTestDB (t , clock )
246238
247239	// Create a few sessions. The first one is a new session and the two 
248240	// after are all linked to the prior one. All these sessions belong to 
@@ -294,18 +286,14 @@ func TestLinkedSessions(t *testing.T) {
294286func  TestStateShift (t  * testing.T ) {
295287	// Set up a new DB. 
296288	clock  :=  clock .NewTestClock (testTime )
297- 	db , err  :=  NewDB (t .TempDir (), "test.db" , clock )
298- 	require .NoError (t , err )
299- 	t .Cleanup (func () {
300- 		_  =  db .Close ()
301- 	})
289+ 	db  :=  NewTestDB (t , clock )
302290
303291	// Add a new session to the DB. 
304292	s1  :=  createSession (t , db , "label 1" )
305293
306294	// Check that the session is in the StateCreated state. Also check that 
307295	// the "RevokedAt" time has not yet been set. 
308- 	s1 , err  =  db .GetSession (s1 .LocalPublicKey )
296+ 	s1 , err  : =  db .GetSession (s1 .LocalPublicKey )
309297	require .NoError (t , err )
310298	require .Equal (t , StateCreated , s1 .State )
311299	require .Equal (t , time.Time {}, s1 .RevokedAt )
0 commit comments