Skip to content

Commit 097dd64

Browse files
author
Mitsuru Nakada
committed
Add backlog_test.go
1 parent e7eb234 commit 097dd64

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

backlog/backlog_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package backlog
2+
3+
import (
4+
"net/url"
5+
"reflect"
6+
"testing"
7+
8+
pointers "github.com/f2prateek/go-pointers"
9+
)
10+
11+
// https://github.com/google/go-github/blob/99760a16213d6fdde13f4e477438f876b6c9c6eb/github/github_test.go#L761-L778
12+
func TestSanitizeURL(t *testing.T) {
13+
tests := []struct {
14+
in, want string
15+
}{
16+
{"/?a=b", "/?a=b"},
17+
{"/?a=b&apiKey=secret", "/?a=b&apiKey=REDACTED"},
18+
{"/?a=b&apiKey=secret&foo=id", "/?a=b&apiKey=REDACTED&foo=id"},
19+
}
20+
21+
for _, tt := range tests {
22+
inURL, _ := url.Parse(tt.in)
23+
want, _ := url.Parse(tt.want)
24+
25+
if got := sanitizeURL(inURL); !reflect.DeepEqual(got, want) {
26+
t.Errorf("sanitizeURL(%v) returned %v, want %v", tt.in, got, want)
27+
}
28+
}
29+
}
30+
31+
func TestAddOptions(t *testing.T) {
32+
request := IssueSearchRequest{
33+
IDs: []int{1, 2, 3},
34+
ParentChild: pointers.Int(1),
35+
Sort: pointers.String("issueType"),
36+
}
37+
38+
u, _ := url.Parse("issues")
39+
v := url.Values{}
40+
v.Add("id[]", "1")
41+
v.Add("id[]", "2")
42+
v.Add("id[]", "3")
43+
v.Add("parentChild", "1")
44+
v.Add("sort", "issueType")
45+
u.RawQuery = v.Encode()
46+
want := u.String()
47+
48+
got, _ := addOptions("issues", request)
49+
if got != want {
50+
t.Errorf("addOptions(%v) returned %v, want %v", request, got, want)
51+
}
52+
}

0 commit comments

Comments
 (0)