-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
45 lines (40 loc) · 1.15 KB
/
main_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
package main
import (
"reflect"
"testing"
)
func TestParseDomains(t *testing.T) {
tests := []struct {
input uint16
expected []int
}{
{input: uint16(0), expected: nil},
{input: uint16(1), expected: []int{1}},
{input: uint16(1 << 3), expected: []int{4}},
{input: uint16(1 + 1<<4), expected: []int{1, 5}},
{input: uint16(1<<2 + 1<<11 + 1<<7), expected: []int{3, 8, 12}},
}
for _, test := range tests {
actual := parseDomains(test.input)
if !reflect.DeepEqual(actual, test.expected) {
t.Errorf("Unexpected result %v, wanted %v", actual, test.expected)
}
}
}
func TestParseCapabilities(t *testing.T) {
tests := []struct {
input uint64
expected []string
}{
{input: uint64(0), expected: nil},
{input: uint64(1), expected: []string{"get_opaque"}},
{input: uint64(1 + 1<<7), expected: []string{"get_opaque", "sign_ecdsa"}},
{input: uint64(1<<7 + 1<<3 + 1), expected: []string{"get_opaque", "put_asymmetric_key", "sign_ecdsa"}},
}
for _, test := range tests {
actual := parseCapabilities(test.input)
if !reflect.DeepEqual(actual, test.expected) {
t.Errorf("Unexpected result %v, wanted %v", actual, test.expected)
}
}
}