-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathopdesktop_test.go
More file actions
72 lines (68 loc) · 1.55 KB
/
opdesktop_test.go
File metadata and controls
72 lines (68 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package keyring
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNewOPDesktopKeyring(t *testing.T) {
testCases := []struct {
name string
cfg Config
expectError error
}{
{
name: "valid configuration",
cfg: Config{
OPTimeout: 5 * time.Second,
OPVaultID: "vaultID",
OPDesktopAccountID: "accountID",
},
expectError: nil,
},
{
name: "missing timeout",
cfg: Config{
OPVaultID: "vaultID",
OPDesktopAccountID: "accountID",
},
expectError: OPDesktopErrTimeout,
},
{
name: "missing vault ID",
cfg: Config{
OPTimeout: 5 * time.Second,
OPDesktopAccountID: "accountID",
},
expectError: OPErrVaultID,
},
{
name: "missing desktop account id",
cfg: Config{
OPTimeout: 5 * time.Second,
OPVaultID: "vaultID",
},
expectError: OPDesktopErrAccountID,
},
{
name: "missing all",
cfg: Config{},
expectError: errors.Join(OPDesktopErrTimeout, OPErrVaultID, OPDesktopErrAccountID),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
keyring, err := NewOPDesktopKeyring(&tc.cfg)
if tc.expectError != nil {
assert.ErrorContains(t, err, tc.expectError.Error())
assert.Nil(t, keyring)
} else {
assert.NoError(t, err)
assert.NotNil(t, keyring)
assert.Equal(t, tc.cfg.OPTimeout, keyring.Timeout)
assert.Equal(t, tc.cfg.OPVaultID, keyring.VaultID)
assert.Equal(t, tc.cfg.OPDesktopAccountID, keyring.DesktopAccountID)
}
})
}
}