-
Notifications
You must be signed in to change notification settings - Fork 46
/
file_uri_test.go
49 lines (42 loc) · 1.2 KB
/
file_uri_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 main
import (
"testing"
)
func TestURI(t *testing.T) {
value := "s3://bucket-name/file.txt"
uri, err := FileURINew(value)
if err != nil || uri.Scheme != "s3" || uri.Bucket != "bucket-name" || *uri.Key() != "file.txt" {
t.Error("error parsing ", value)
}
if uri.String() != value {
t.Error("roundtrip ", value, uri.String())
}
value = "xxx://bucket-name/a/b/c/file.txt"
uri, err = FileURINew("xxx://bucket-name/a/b/c/file.txt")
if err == nil {
t.Error("error parsing ", value)
}
value = "test/of/test.txt"
uri, err = FileURINew(value)
if err != nil {
t.Error("error parsing ", value)
}
if uri.Path != "test/of/test.txt" || uri.Scheme != "file" || uri.Bucket != "" {
t.Error("error parsing ", value)
}
if uri.String() != "file://test/of/test.txt" {
t.Error("roundtrip ", value, uri.String())
}
// Test joins -- first file
value = "test/of/test.txt"
uri, err = FileURINew(value)
if err != nil {
t.Error("error parsing ", value)
}
if turi := uri.Join("/new/file.txt"); turi.Path != "/new/file.txt" {
t.Error("error join /new/file.txt", turi.Path)
}
if turi := uri.Join("new/file.txt"); turi.Path != "test/of/new/file.txt" {
t.Error("error join new/file.txt", turi.Path)
}
}