-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
keychain_mac_test.go
46 lines (38 loc) · 1.27 KB
/
keychain_mac_test.go
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
// +build darwin,amd64
package main
import (
"errors"
"testing"
"github.com/keybase/go-keychain"
"github.com/stretchr/testify/require"
)
func Test_keychainFetcher_NoKeychainError(t *testing.T) {
defaultKeychain = func(serviceLabel string) ([]keychain.QueryResult, error) {
return nil, errors.New("error")
}
_, err := keychainFetcher("ff")
require.Equal(t, "unable to connect to keychain", err.Error())
}
func Test_keychainFetcher_NoItemFoundError(t *testing.T) {
defaultKeychain = func(serviceLabel string) ([]keychain.QueryResult, error) {
return nil, nil
}
_, err := keychainFetcher("ff")
require.Equal(t, "item doesn't exist", err.Error())
}
func Test_keychainFetcher_ToManyMatching(t *testing.T) {
defaultKeychain = func(serviceLabel string) ([]keychain.QueryResult, error) {
return []keychain.QueryResult{{Data: []byte("foo")}, {Data: []byte("foo")}}, nil
}
_, err := keychainFetcher("ff")
require.Equal(t, "too many matching items", err.Error())
}
func Test_keychainFetcher_ItemFound(t *testing.T) {
var expected = "RSA"
defaultKeychain = func(serviceLabel string) ([]keychain.QueryResult, error) {
return []keychain.QueryResult{{Data: []byte(expected)}}, nil
}
actual, err := keychainFetcher("ff")
require.Contains(t, expected, actual)
require.Nil(t, err)
}