MCPcopy Index your code
hub / github.com/docker/cli / TestMemoryStore

Function TestMemoryStore

cli/config/memorystore/store_test.go:11–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestMemoryStore(t *testing.T) {
12 config := map[string]types.AuthConfig{
13 "https://example.test": {
14 Username: "something-something",
15 ServerAddress: "https://example.test",
16 Auth: "super_secret_token",
17 },
18 }
19
20 fallbackConfig := map[string]types.AuthConfig{
21 "https://only-in-file.example.test": {
22 Username: "something-something",
23 ServerAddress: "https://only-in-file.example.test",
24 Auth: "super_secret_token",
25 },
26 }
27
28 fallbackStore, err := New(WithAuthConfig(fallbackConfig))
29 assert.NilError(t, err)
30
31 memoryStore, err := New(WithAuthConfig(config), WithFallbackStore(fallbackStore))
32 assert.NilError(t, err)
33
34 t.Run("get credentials from memory store", func(t *testing.T) {
35 c, err := memoryStore.Get("https://example.test")
36 assert.NilError(t, err)
37 assert.Equal(t, c, config["https://example.test"])
38 })
39
40 t.Run("get credentials from fallback store", func(t *testing.T) {
41 c, err := memoryStore.Get("https://only-in-file.example.test")
42 assert.NilError(t, err)
43 assert.Equal(t, c, fallbackConfig["https://only-in-file.example.test"])
44 })
45
46 t.Run("storing credentials in memory store should also be in defined fallback store", func(t *testing.T) {
47 err := memoryStore.Store(types.AuthConfig{
48 Username: "not-in-store",
49 ServerAddress: "https://not-in-store.example.test",
50 Auth: "not-in-store_token",
51 })
52 assert.NilError(t, err)
53 c, err := memoryStore.Get("https://not-in-store.example.test")
54 assert.NilError(t, err)
55 assert.Equal(t, c.Username, "not-in-store")
56 assert.Equal(t, c.ServerAddress, "https://not-in-store.example.test")
57 assert.Equal(t, c.Auth, "not-in-store_token")
58
59 cc, err := fallbackStore.Get("https://not-in-store.example.test")
60 assert.NilError(t, err)
61 assert.Equal(t, cc.Username, "not-in-store")
62 assert.Equal(t, cc.ServerAddress, "https://not-in-store.example.test")
63 assert.Equal(t, cc.Auth, "not-in-store_token")
64 })
65
66 t.Run("delete credentials should remove credentials from memory store and fallback store", func(t *testing.T) {
67 err := memoryStore.Store(types.AuthConfig{
68 Username: "a-new-credential",

Callers

nothing calls this directly

Calls 6

WithAuthConfigFunction · 0.85
WithFallbackStoreFunction · 0.85
NewFunction · 0.70
GetMethod · 0.65
StoreMethod · 0.65
EraseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…