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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package datafs
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSplitFSMuxURL(t *testing.T) {
testdata := []struct {
in string
url string
file string
}{
{
"http://example.com/foo.json",
"http://example.com/",
"foo.json",
},
{
"http://example.com/foo.json?type=application/array+yaml",
"http://example.com/?type=application/array+yaml",
"foo.json",
},
{
"vault:///secret/a/b/c",
"vault:///",
"secret/a/b/c",
},
{
"vault:///secret/a/b/",
"vault:///",
"secret/a/b",
},
{
"s3://bucket/a/b/",
"s3://bucket/",
"a/b",
},
{
"vault:///foo/bar",
"vault:///",
"foo/bar",
},
{
"consul://myhost/foo/bar/baz?q=1",
"consul://myhost/?q=1",
"foo/bar/baz",
},
{
"git+https://example.com/myrepo//foo.yaml",
"git+https://example.com/myrepo",
"foo.yaml",
},
{
"git+https://example.com/myrepo//",
"git+https://example.com/myrepo",
".",
},
{
// git repos are special - no double-slash means the root
"git+https://example.com/myrepo",
"git+https://example.com/myrepo",
".",
},
{
"git+ssh://git@github.com/hairyhenderson/go-which.git//a/b/c/d?q=1",
"git+ssh://git@github.com/hairyhenderson/go-which.git?q=1",
"a/b/c/d",
},
{
"merge:file:///tmp/jsonfile.json",
"merge:///",
"file:///tmp/jsonfile.json",
},
{
"merge:a|b",
"merge:///",
"a|b",
},
{
"merge:a|b|c|d|e",
"merge:///",
"a|b|c|d|e",
},
{
"merge:foo/bar/baz.json|qux",
"merge:///",
"foo/bar/baz.json|qux",
},
{
"merge:vault:///foo/bar|foo|git+ssh://git@github.com/hairyhenderson/go-which.git//a/b/c/d",
"merge:///",
"vault:///foo/bar|foo|git+ssh://git@github.com/hairyhenderson/go-which.git//a/b/c/d",
},
{
"aws+sm:foo",
"aws+sm:",
"foo",
},
{
"aws+sm:foo/bar",
"aws+sm:",
"foo/bar",
},
{
"aws+sm:/foo/bar",
"aws+sm:///",
"foo/bar",
},
{
"aws+sm:/foo",
"aws+sm:///",
"foo",
},
}
for _, d := range testdata {
u, err := url.Parse(d.in)
require.NoError(t, err)
url, file := SplitFSMuxURL(u)
assert.Equal(t, d.url, url.String())
assert.Equal(t, d.file, file)
}
}
|