-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams_test.go
More file actions
36 lines (31 loc) · 991 Bytes
/
params_test.go
File metadata and controls
36 lines (31 loc) · 991 Bytes
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
package forge
import "testing"
func TestResolvePath_Good_Simple(t *testing.T) {
got := ResolvePath("/api/v1/repos/{owner}/{repo}", Params{"owner": "core", "repo": "go-forge"})
want := "/api/v1/repos/core/go-forge"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
func TestResolvePath_Good_NoParams(t *testing.T) {
got := ResolvePath("/api/v1/user", nil)
if got != "/api/v1/user" {
t.Errorf("got %q", got)
}
}
func TestResolvePath_Good_WithID(t *testing.T) {
got := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}", Params{
"owner": "core", "repo": "go-forge", "index": "42",
})
want := "/api/v1/repos/core/go-forge/issues/42"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
func TestResolvePath_Good_URLEncoding(t *testing.T) {
got := ResolvePath("/api/v1/repos/{owner}/{repo}", Params{"owner": "my org", "repo": "my repo"})
want := "/api/v1/repos/my%20org/my%20repo"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}