-
Notifications
You must be signed in to change notification settings - Fork 660
/
test_aliases.go
108 lines (83 loc) · 2.86 KB
/
test_aliases.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ids
import (
"github.com/stretchr/testify/assert"
)
var AliasTests = []func(assert *assert.Assertions, r AliaserReader, w AliaserWriter){
AliaserLookupErrorTest,
AliaserLookupTest,
AliaserAliasesEmptyTest,
AliaserAliasesTest,
AliaserPrimaryAliasTest,
AliaserAliasClashTest,
AliaserRemoveAliasTest,
}
func AliaserLookupErrorTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
_, err := r.Lookup("Batman")
assert.Error(err, "expected an error due to missing alias")
}
func AliaserLookupTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id := ID{'K', 'a', 't', 'e', ' ', 'K', 'a', 'n', 'e'}
err := w.Alias(id, "Batwoman")
assert.NoError(err)
res, err := r.Lookup("Batwoman")
assert.NoError(err)
assert.Equal(id, res)
}
func AliaserAliasesEmptyTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id := ID{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'}
aliases, err := r.Aliases(id)
assert.NoError(err)
assert.Empty(aliases)
}
func AliaserAliasesTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'}
err := w.Alias(id, "Batman")
assert.NoError(err)
err = w.Alias(id, "Dark Knight")
assert.NoError(err)
aliases, err := r.Aliases(id)
assert.NoError(err)
expected := []string{"Batman", "Dark Knight"}
assert.Equal(expected, aliases)
}
func AliaserPrimaryAliasTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id1 := ID{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'}
id2 := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'}
err := w.Alias(id2, "Batman")
assert.NoError(err)
err = w.Alias(id2, "Dark Knight")
assert.NoError(err)
_, err = r.PrimaryAlias(id1)
assert.Error(err)
expected := "Batman"
res, err := r.PrimaryAlias(id2)
assert.NoError(err)
assert.Equal(expected, res)
}
func AliaserAliasClashTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id1 := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'}
id2 := ID{'D', 'i', 'c', 'k', ' ', 'G', 'r', 'a', 'y', 's', 'o', 'n'}
err := w.Alias(id1, "Batman")
assert.NoError(err)
err = w.Alias(id2, "Batman")
assert.Error(err)
}
func AliaserRemoveAliasTest(assert *assert.Assertions, r AliaserReader, w AliaserWriter) {
id1 := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'}
id2 := ID{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'}
err := w.Alias(id1, "Batman")
assert.NoError(err)
err = w.Alias(id1, "Dark Knight")
assert.NoError(err)
w.RemoveAliases(id1)
_, err = r.PrimaryAlias(id1)
assert.Error(err)
err = w.Alias(id2, "Batman")
assert.NoError(err)
err = w.Alias(id2, "Dark Knight")
assert.NoError(err)
err = w.Alias(id1, "Dark Night Rises")
assert.NoError(err)
}