-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
changes_hashtags_test.go
88 lines (78 loc) · 1.77 KB
/
changes_hashtags_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gerrit_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/andygrunwald/go-gerrit"
)
func TestChangesService_GetHashtags(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
const (
method = "GET"
path = "/changes/123/hashtags"
)
if r.Method != method {
t.Errorf("Method %q != %q", r.Method, method)
}
if r.URL.Path != path {
t.Errorf("Path %q != %q", r.URL.Path, path)
}
fmt.Fprintf(w, `)]}'
[
"hashtag1",
"hashtag2"
]
`)
}))
defer ts.Close()
ctx := context.Background()
client, err := gerrit.NewClient(ctx, ts.URL, nil)
if err != nil {
t.Fatal(err)
}
hashtags, _, err := client.Changes.GetHashtags(ctx, "123")
if err != nil {
t.Fatal(err)
}
if len(hashtags) != 2 || hashtags[0] != "hashtag1" || hashtags[1] != "hashtag2" {
t.Errorf("Unexpected hashtags %+v", hashtags)
}
}
func TestChangesService_SetHashtags(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
const (
method = "POST"
path = "/changes/123/hashtags"
)
if r.Method != method {
t.Errorf("Method %q != %q", r.Method, method)
}
if r.URL.Path != path {
t.Errorf("Path %q != %q", r.URL.Path, path)
}
fmt.Fprintf(w, `)]}'
[
"hashtag1",
"hashtag3"
]
`)
}))
defer ts.Close()
ctx := context.Background()
client, err := gerrit.NewClient(ctx, ts.URL, nil)
if err != nil {
t.Fatal(err)
}
hashtags, _, err := client.Changes.SetHashtags(ctx, "123", &gerrit.HashtagsInput{
Add: []string{"hashtag3"},
Remove: []string{"hashtag2"},
})
if err != nil {
t.Fatal(err)
}
if len(hashtags) != 2 || hashtags[0] != "hashtag1" || hashtags[1] != "hashtag3" {
t.Errorf("Unexpected hashtags %+v", hashtags)
}
}