-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfs_test.go
69 lines (61 loc) · 1.44 KB
/
fs_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
61
62
63
64
65
66
67
68
69
package qfs
import (
"os"
"path/filepath"
"testing"
)
func TestAbsPath(t *testing.T) {
tmp, err := filepath.Abs(os.TempDir())
if err != nil {
t.Fatal(err)
}
pathAbs, err := filepath.Abs("relative/path/data.yaml")
if err != nil {
t.Fatal(err)
}
httpAbs, err := filepath.Abs("http_got/relative/dataset.yaml")
if err != nil {
t.Fatal(err)
}
cases := []struct {
in, out, err string
}{
{"", "", ""},
{"http://example.com/zipfile.zip", "http://example.com/zipfile.zip", ""},
{"https://example.com/zipfile.zip", "https://example.com/zipfile.zip", ""},
{"relative/path/data.yaml", pathAbs, ""},
{"http_got/relative/dataset.yaml", httpAbs, ""},
{"/ipfs", "/ipfs", ""},
{tmp, tmp, ""},
}
for i, c := range cases {
got := c.in
err := AbsPath(&got)
if !(err == nil && c.err == "" || (err != nil && c.err == err.Error())) {
t.Errorf("case %d error mismatch. expected: %s, got: %s", i, c.err, err)
}
if got != c.out {
t.Errorf("case %d error mismatch. expected: %s, got: %s", i, c.out, got)
}
}
}
func TestPathKind(t *testing.T) {
cases := []struct {
in, out string
}{
{"", "none"},
{"http://example", "http"},
{"https://example", "http"},
{"/path/to/location", "local"},
{"/", "local"},
{"/ipfs/Qmfoo", "ipfs"},
{"/mem/Qmfoo", "mem"},
{"/map/Qmfoo", "map"},
}
for i, c := range cases {
got := PathKind(c.in)
if got != c.out {
t.Errorf("case %d: expected: %s, got :%s", i, c.out, got)
}
}
}