forked from mattn/lastpass-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
search_test.go
48 lines (44 loc) · 1.62 KB
/
search_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
47
48
package lastpass
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestMatchFuncs(t *testing.T) {
testCases := []struct {
name string
val string
matcher string
searchM SearchMethod
match bool
}{
{"substring url", "m.facebook.com", "facebook.com", SubstringSensitive, true},
{"substring not in url", "facebook.com", "facsebook.com", SubstringInsensitive, false},
{"substring in url", "https://stackoverflow.com/", "StackOverflow", SubstringInsensitive, true},
{"regex in url", "https://stackOverflow.com/", `(s|S)tack(O|o)verflow`, Regex, true},
{"case insens url", "youtube.com", "YouTube.com", CaseInsensitive, true},
{"case sens ID", "8675309", "8675309", CaseSensitive, true},
{"case insens email", "[email protected]", `@gmail.com`, CaseSensitive, false},
{"regex subdomains only", "m.cnn.com", `.+\.cnn\.com`, Regex, true},
{"regex no subdmomains", "fakenews.com", `^fakenews\.com`, Regex, true},
}
for _, tc := range testCases {
t.Run(tc.name, func(subT *testing.T) {
actual := matchFuncs[tc.searchM](tc.val, tc.matcher)
assert.Equal(subT, tc.match, actual, fmt.Sprintf("%v", tc))
})
}
}
func TestAccountGetValue(t *testing.T) {
account := Account{
Id: "8675309",
Username: "followmeontwitter",
Url: "https://twitter.com/",
Name: "Twitter",
}
assert.Equal(t, account.Id, getValue(account, Id))
assert.Equal(t, account.Username, getValue(account, Username))
assert.Equal(t, account.Url, getValue(account, Url))
assert.Equal(t, account.Name, getValue(account, Name))
assert.Equal(t, account.Id, getValue(account, Field(uint32(65165165))))
}