-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We had 2 copies of this logic in the code and this bit me when I introduced id-based shards indexbuilder.go seems an "ok" place to put. We cannot put it in the shards package because of circular dependencies. Test plan: refactor, so relying on CI
- Loading branch information
1 parent
c03b77f
commit 8d28d72
Showing
6 changed files
with
68 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters