-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeys_test.go
53 lines (48 loc) · 1.51 KB
/
keys_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
49
50
51
52
53
package keys
import (
"errors"
"reflect"
"testing"
)
var substringTests = []struct {
in string
start string
end string
out string
err error
}{
{"hello world", "hello", "", " world", nil},
{"hello world", "", "world", "hello ", nil},
{"hello world", "", "", "hello world", nil},
{"", "", "", "", nil},
{"hello world", "should_produce_error", "", "", errors.New("")},
}
func TestSubstring(t *testing.T) {
for _, substringTest := range substringTests {
substr, err := subString(substringTest.in, substringTest.start, substringTest.end)
if (err != nil && substringTest.err == nil) || (err == nil && substringTest.err != nil) {
t.Errorf("got an unexpected number of errors")
} else if substr != substringTest.out {
t.Errorf("got %q, want %q", substr, substringTest.out)
}
}
}
func TestAppendSlice(t *testing.T) {
sliceOne := make([]Key, 0)
accountOne := "account-one"
keyOne := Key{accountOne, "", 0, "", 1, "", Provider{"", "", ""}, "Active"}
sliceOne = append(sliceOne, keyOne)
sliceTwo := make([]Key, 0)
accountTwo := "account-two"
keyTwo := Key{accountTwo, "", 2, "", 3, "", Provider{"", "", ""}, "Active"}
sliceTwo = append(sliceTwo, keyTwo)
appendedSlice := appendSlice(sliceOne, sliceTwo)
if !reflect.DeepEqual(appendedSlice[0], keyOne) {
t.Errorf("Incorrect key returned in slice, got: %+v, want: %+v.",
appendedSlice[0], keyOne)
}
if !reflect.DeepEqual(appendedSlice[1], keyTwo) {
t.Errorf("Incorrect key returned in slice, got: %+v, want: %+v.",
appendedSlice[1], keyTwo)
}
}