forked from sourcegraph/zoekt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindexbuilder_test.go
49 lines (46 loc) · 967 Bytes
/
indexbuilder_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
package zoekt
import (
"strings"
"testing"
)
func TestShardName(t *testing.T) {
tests := []struct {
name string
indexDir string
prefix string
version int
shardNum int
expected string
}{
{
name: "short prefix",
indexDir: "index",
prefix: "short",
version: 1,
shardNum: 42,
expected: "index/short_v1.00042.zoekt",
},
{
name: "long prefix truncated",
indexDir: "index",
prefix: strings.Repeat("a", 300),
version: 2,
shardNum: 1,
expected: "index/" + strings.Repeat("a", 200) + "003ef1ba" + "_v2.00001.zoekt",
},
{
name: "empty indexDir",
prefix: "short",
version: 1,
expected: "short_v1.00000.zoekt",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := ShardName(test.indexDir, test.prefix, test.version, test.shardNum)
if actual != test.expected {
t.Errorf("expected %q, got %q", test.expected, actual)
}
})
}
}