Skip to content

Commit 494ef7a

Browse files
committed
store/keychain: fix test on list credentials
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent eaf010a commit 494ef7a

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

store/keychain/keychain_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package keychain
22

33
import (
44
"errors"
5-
"slices"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
@@ -111,10 +110,16 @@ func TestKeychain(t *testing.T) {
111110
"com.test.test/test/bob": {
112111
Username: "bob",
113112
Password: "bob-password",
113+
Attributes: map[string]string{
114+
"color": "green",
115+
},
114116
},
115117
"com.test.test/test/jeff": {
116118
Username: "jeff",
117119
Password: "jeff-password",
120+
Attributes: map[string]string{
121+
"game": "elden ring",
122+
},
118123
},
119124
"com.test.test/test/pete": {
120125
Username: "pete",
@@ -134,18 +139,29 @@ func TestKeychain(t *testing.T) {
134139
require.NoError(t, err)
135140
require.Len(t, secrets, 3)
136141

137-
expected := make([]store.ID, 0, 3)
138-
for k := range moreCreds {
139-
expected = append(expected, k)
142+
actual := make(map[store.ID]*mocks.MockCredential)
143+
for k, v := range secrets {
144+
actual[k] = v.(*mocks.MockCredential)
140145
}
141-
slices.Sort(expected)
142146

143-
actual := make([]store.ID, 0, 3)
144-
for key := range secrets {
145-
actual = append(actual, key)
147+
expected := moreCreds
148+
for k, v := range expected {
149+
// listing credentials from the store won't retrieve the actual
150+
// credentials, only the metadata.
151+
// That is why we set username and password to empty
152+
v.Username = ""
153+
v.Password = ""
154+
155+
// the store sets some attributes internally, which we need to setup
156+
// here on our expected map.
157+
if v.Attributes == nil {
158+
v.Attributes = make(map[string]string)
159+
}
160+
v.Attributes["id"] = k.String()
161+
v.Attributes["service:group"] = "com.test.test"
162+
v.Attributes["service:name"] = "test"
146163
}
147-
slices.Sort(actual)
148-
require.Equal(t, expected, actual)
164+
assert.EqualValues(t, expected, actual)
149165
})
150166

151167
t.Run("filter credentials", func(t *testing.T) {

0 commit comments

Comments
 (0)