-
Notifications
You must be signed in to change notification settings - Fork 255
/
Copy pathlib_test.go
60 lines (55 loc) · 1.72 KB
/
lib_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
57
58
59
60
package main
import (
"fmt"
"reflect"
"strings"
"testing"
)
// ensure the path hashing function doesn't change
func Test_key2path(t *testing.T) {
tests := map[string]string{
"hello": "/5d/41/aGVsbG8=",
"helloworld": "/fc/5e/aGVsbG93b3JsZA==",
}
for k, v := range tests {
ret := key2path([]byte(k))
if ret != v {
t.Fatal("key2path function broke", k, ret, v)
}
}
}
// ensure the volume hashing function doesn't change
func Test_key2volume(t *testing.T) {
volumes := []string{"larry", "moe", "curly"}
tests := map[string]string{
"hello": "larry",
"helloworld": "curly",
"world": "moe",
"blah": "curly",
}
for k, v := range tests {
ret := key2volume([]byte(k), volumes, 1, 3)
if strings.Split(ret[0], "/")[0] != v {
t.Fatal("key2volume function broke", k, ret, v)
}
}
}
func fromToRecordExample(t *testing.T, rec Record, val string) {
recs := fromRecord(rec)
if val != string(recs) {
t.Fatal("record string didn't match")
}
reca := toRecord(recs)
if !reflect.DeepEqual(rec, reca) {
t.Fatal("toRecord(fromRecord(rec)) failed")
}
fmt.Println(val)
}
func Test_fromToRecord(t *testing.T) {
fromToRecordExample(t, Record{[]string{"hello", "world"}, SOFT, ""}, "DELETEDhello,world")
fromToRecordExample(t, Record{[]string{"hello", "world"}, NO, ""}, "hello,world")
fromToRecordExample(t, Record{[]string{"hello"}, NO, ""}, "hello")
fromToRecordExample(t, Record{[]string{"hello"}, SOFT, ""}, "DELETEDhello")
fromToRecordExample(t, Record{[]string{"hello"}, SOFT, "5d41402abc4b2a76b9719d911017c592"}, "DELETEDHASH5d41402abc4b2a76b9719d911017c592hello")
fromToRecordExample(t, Record{[]string{"hello"}, NO, "5d41402abc4b2a76b9719d911017c592"}, "HASH5d41402abc4b2a76b9719d911017c592hello")
}