@@ -52,6 +52,12 @@ func (t *testStore) Delete(ctx context.Context, serverAddress string) error {
5252
5353type badStore struct {}
5454
55+ type contextErrorStore struct { Store }
56+
57+ func (contextErrorStore ) Get (ctx context.Context , _ string ) (Credential , error ) {
58+ return EmptyCredential , ctx .Err ()
59+ }
60+
5561var errBadStore = errors .New ("bad store!" )
5662
5763// Get retrieves credentials from the store for the given server address.
@@ -1179,6 +1185,37 @@ func Test_inheritedHelperStore_Get_helperError(t *testing.T) {
11791185 }
11801186}
11811187
1188+ func Test_inheritedHelperStore_Get_success (t * testing.T ) {
1189+ address := "example.com/team/app"
1190+ want := Credential {Username : "username" , Password : "password" }
1191+ store := inheritedHelperStore {& testStore {storage : map [string ]Credential {address : want }}}
1192+ got , err := store .Get (context .Background (), address )
1193+ if err != nil {
1194+ t .Fatal ("inheritedHelperStore.Get() error =" , err )
1195+ }
1196+ if got != want {
1197+ t .Errorf ("inheritedHelperStore.Get() = %v, want %v" , got , want )
1198+ }
1199+ }
1200+
1201+ func Test_inheritedHelperStore_Get_contextError (t * testing.T ) {
1202+ store := inheritedHelperStore {contextErrorStore {}}
1203+ canceled , cancel := context .WithCancel (context .Background ())
1204+ cancel ()
1205+ deadline , stop := context .WithTimeout (context .Background (), 0 )
1206+ defer stop ()
1207+
1208+ for _ , ctx := range []context.Context {canceled , deadline } {
1209+ got , err := store .Get (ctx , "example.com/team/app" )
1210+ if ! errors .Is (err , ctx .Err ()) {
1211+ t .Errorf ("inheritedHelperStore.Get() error = %v, want %v" , err , ctx .Err ())
1212+ }
1213+ if got != EmptyCredential {
1214+ t .Errorf ("inheritedHelperStore.Get() = %v, want %v" , got , EmptyCredential )
1215+ }
1216+ }
1217+ }
1218+
11821219func Test_inheritedHelperStore_Put_helperError (t * testing.T ) {
11831220 store := inheritedHelperStore {& nativeStore {& testExecuter {}}}
11841221 if err := store .Put (context .Background (), "localhost:500/unknown" , Credential {}); err == nil {
0 commit comments