-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
64 lines (59 loc) · 1.24 KB
/
utils_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
package kittycad
import (
"net/url"
"testing"
)
type expandTest struct {
in string
expansions map[string]string
want string
}
func TestExpandURL(t *testing.T) {
var testServerURL = "http://example.com"
var expandTests = []expandTest{
// no expansions
{
"",
map[string]string{},
testServerURL,
},
// multiple expansions, no escaping
{
"file/convert/{{.srcFormat}}/{{.outputFormat}}",
map[string]string{
"srcFormat": "step",
"outputFormat": "obj",
},
testServerURL + "/file/convert/step/obj",
},
// Path params added as extras.
{
"file/convert",
map[string]string{
"srcFormat": "step",
"outputFormat": "obj",
},
testServerURL + "/file/convert?outputFormat=obj&srcFormat=step",
},
// Path params added as extras.
{
"file/mass",
map[string]string{
"unit": "kg:m3",
},
testServerURL + "/file/mass?unit=kg:m3",
},
}
for i, test := range expandTests {
uri := resolveRelative(testServerURL, test.in)
u, err := url.Parse(uri)
if err != nil {
t.Fatalf("parsing url %q failed: %v", test.in, err)
}
expandURL(u, test.expansions)
got := u.String()
if got != test.want {
t.Errorf("got %q expected %q in test %d", got, test.want, i+1)
}
}
}