-
Notifications
You must be signed in to change notification settings - Fork 5
/
identity_test.go
56 lines (49 loc) · 1.13 KB
/
identity_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
54
55
56
package handel
import (
"testing"
"github.com/stretchr/testify/require"
)
type registryTest struct {
reg func() Registry
expectedSize int
// single identity test
getIdx int
getFound bool
getIdentity Identity
// range test
from int
to int
found bool
identities []Identity
}
func TestRegistryArray(t *testing.T) {
n := 10
registry := FakeRegistry(n).(*arrayRegistry)
ids := registry.ids
nf := func() Registry { return registry }
var tests = []registryTest{
{
nf, 10, 1, true, ids[1], 0, 3, true, ids[0:3],
},
{
nf, 10, -1, false, nil, 0, 11, false, nil,
},
}
testRegistryTests(t, tests)
}
func testRegistryTests(t *testing.T, tests []registryTest) {
for _, test := range tests {
registry := test.reg()
require.Equal(t, test.expectedSize, registry.Size())
id, found := registry.Identity(test.getIdx)
require.Equal(t, test.getFound, found)
if found {
require.Equal(t, test.getIdentity, id)
}
ids, rangeFound := registry.Identities(test.from, test.to)
require.Equal(t, test.found, rangeFound)
if rangeFound {
require.Equal(t, test.identities, ids)
}
}
}