11package keychain
22
33import (
4- "context"
54 "maps"
65 "testing"
76
@@ -11,9 +10,6 @@ import (
1110)
1211
1312func TestKeychain (t * testing.T ) {
14- mainCtx , mainCtxCancel := context .WithCancel (context .Background ())
15- t .Cleanup (mainCtxCancel )
16-
1713 ks , err := New ("com.test.test" , "test" ,
1814 func () * mocks.MockCredential {
1915 return & mocks.MockCredential {}
@@ -22,25 +18,19 @@ func TestKeychain(t *testing.T) {
2218 require .NoError (t , err )
2319
2420 t .Run ("save credentials" , func (t * testing.T ) {
25- ctx , cancel := context .WithCancel (mainCtx )
26- t .Cleanup (cancel )
27-
2821 id := store .ID ("com.test.test/test/bob" )
2922 require .NoError (t , id .Valid ())
3023 creds := & mocks.MockCredential {
3124 Username : "bob" ,
3225 Password : "bob-password" ,
3326 }
34- require .NoError (t , ks .Save (ctx , id , creds ))
27+ require .NoError (t , ks .Save (t . Context () , id , creds ))
3528 })
3629
3730 t .Run ("get credential" , func (t * testing.T ) {
38- ctx , cancel := context .WithCancel (mainCtx )
39- t .Cleanup (cancel )
40-
4131 id := store .ID ("com.test.test/test/bob" )
4232 require .NoError (t , id .Valid ())
43- secret , err := ks .Get (ctx , id )
33+ secret , err := ks .Get (t . Context () , id )
4434 require .NoError (t , err )
4535
4636 actual , ok := secret .(* mocks.MockCredential )
@@ -54,9 +44,6 @@ func TestKeychain(t *testing.T) {
5444 })
5545
5646 t .Run ("list all credentials" , func (t * testing.T ) {
57- ctx , cancel := context .WithCancel (mainCtx )
58- t .Cleanup (cancel )
59-
6047 moreCreds := map [store.ID ]* mocks.MockCredential {
6148 "com.test.test/test/jeff" : {
6249 Username : "jeff" ,
@@ -69,9 +56,9 @@ func TestKeychain(t *testing.T) {
6956 }
7057
7158 for id , anotherCred := range moreCreds {
72- require .NoError (t , ks .Save (ctx , id , anotherCred ))
59+ require .NoError (t , ks .Save (t . Context () , id , anotherCred ))
7360 }
74- secrets , err := ks .GetAll (ctx )
61+ secrets , err := ks .GetAll (t . Context () )
7562 require .NoError (t , err )
7663
7764 actual := make (map [store.ID ]* mocks.MockCredential )
@@ -92,13 +79,10 @@ func TestKeychain(t *testing.T) {
9279 })
9380
9481 t .Run ("delete credential" , func (t * testing.T ) {
95- ctx , cancel := context .WithCancel (mainCtx )
96- t .Cleanup (cancel )
97-
9882 id := store .ID ("com.test.test/test/bob" )
9983 require .NoError (t , id .Valid ())
100- require .NoError (t , ks .Delete (ctx , id ))
101- _ , err := ks .Get (ctx , id )
84+ require .NoError (t , ks .Delete (t . Context () , id ))
85+ _ , err := ks .Get (t . Context () , id )
10286 require .ErrorIs (t , err , store .ErrCredentialNotFound )
10387 })
10488}
0 commit comments