(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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", |
nothing calls this directly
no test coverage detected
searching dependent graphs…