...
1 package test
2
3 import (
4 "github.com/docker/cli/cli/config/credentials"
5 "github.com/docker/cli/cli/config/types"
6 )
7
8
9 type FakeStore struct {
10 store map[string]types.AuthConfig
11 eraseFunc func(serverAddress string) error
12 getFunc func(serverAddress string) (types.AuthConfig, error)
13 getAllFunc func() (map[string]types.AuthConfig, error)
14 storeFunc func(authConfig types.AuthConfig) error
15 }
16
17
18 func NewFakeStore() credentials.Store {
19 return &FakeStore{store: map[string]types.AuthConfig{}}
20 }
21
22
23 func (c *FakeStore) SetStore(store map[string]types.AuthConfig) {
24 c.store = store
25 }
26
27
28 func (c *FakeStore) SetEraseFunc(eraseFunc func(string) error) {
29 c.eraseFunc = eraseFunc
30 }
31
32
33 func (c *FakeStore) SetGetFunc(getFunc func(string) (types.AuthConfig, error)) {
34 c.getFunc = getFunc
35 }
36
37
38 func (c *FakeStore) SetGetAllFunc(getAllFunc func() (map[string]types.AuthConfig, error)) {
39 c.getAllFunc = getAllFunc
40 }
41
42
43 func (c *FakeStore) SetStoreFunc(storeFunc func(types.AuthConfig) error) {
44 c.storeFunc = storeFunc
45 }
46
47
48 func (c *FakeStore) Erase(serverAddress string) error {
49 if c.eraseFunc != nil {
50 return c.eraseFunc(serverAddress)
51 }
52 delete(c.store, serverAddress)
53 return nil
54 }
55
56
57 func (c *FakeStore) Get(serverAddress string) (types.AuthConfig, error) {
58 if c.getFunc != nil {
59 return c.getFunc(serverAddress)
60 }
61 return c.store[serverAddress], nil
62 }
63
64
65 func (c *FakeStore) GetAll() (map[string]types.AuthConfig, error) {
66 if c.getAllFunc != nil {
67 return c.getAllFunc()
68 }
69 return c.store, nil
70 }
71
72
73 func (c *FakeStore) Store(authConfig types.AuthConfig) error {
74 if c.storeFunc != nil {
75 return c.storeFunc(authConfig)
76 }
77 c.store[authConfig.ServerAddress] = authConfig
78 return nil
79 }
80
View as plain text