master
go 65 lines 1.2 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package secretstore
4
5 import (
6 "context"
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 type testPublishedStore struct{}
13
14 func (testPublishedStore) Resolve(_ context.Context, _ ResolveRequest) (string, error) {
15 return "", nil
16 }
17
18 func TestSnapshotLookupStore(t *testing.T) {
19 tests := map[string]struct {
20 snapshot *Snapshot
21 id string
22 wantOK bool
23 }{
24 "nil snapshot": {
25 snapshot: nil,
26 id: "s1",
27 wantOK: false,
28 },
29 "empty stores map": {
30 snapshot: &Snapshot{stores: map[string]publishedRecord{}},
31 id: "s1",
32 wantOK: false,
33 },
34 "not found": {
35 snapshot: &Snapshot{
36 stores: map[string]publishedRecord{
37 "s1": {},
38 },
39 },
40 id: "s2",
41 wantOK: false,
42 },
43 "found": {
44 snapshot: &Snapshot{
45 stores: map[string]publishedRecord{
46 "s1": {published: testPublishedStore{}},
47 },
48 },
49 id: "s1",
50 wantOK: true,
51 },
52 }
53
54 for name, tc := range tests {
55 t.Run(name, func(t *testing.T) {
56 store, ok := tc.snapshot.lookupStore(tc.id)
57 if !assert.Equal(t, tc.wantOK, ok, "lookupStore(%q) ok mismatch", tc.id) {
58 return
59 }
60 if ok {
61 assert.NotNil(t, store.published)
62 }
63 })
64 }
65 }