-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
changes_revision_test.go
84 lines (78 loc) · 2.09 KB
/
changes_revision_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
package gerrit_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/andygrunwald/go-gerrit"
)
func TestChangesService_ListFiles(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?base=7"; got != want {
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want)
}
fmt.Fprint(w, `{
"/COMMIT_MSG": {
"status": "A",
"lines_inserted": 7,
"size_delta": 551,
"size": 551
},
"gerrit-server/RefControl.java": {
"lines_inserted": 5,
"lines_deleted": 3,
"size_delta": 98,
"size": 23348
}
}`)
}))
defer ts.Close()
ctx := context.Background()
client := newClient(ctx, t, ts)
got, _, err := client.Changes.ListFiles(ctx, "123", "456", &gerrit.FilesOptions{
Base: "7",
})
if err != nil {
t.Fatal(err)
}
want := map[string]gerrit.FileInfo{
"/COMMIT_MSG": {
Status: "A",
LinesInserted: 7,
SizeDelta: 551,
Size: 551,
},
"gerrit-server/RefControl.java": {
LinesInserted: 5,
LinesDeleted: 3,
SizeDelta: 98,
Size: 23348,
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("client.Changes.ListFiles:\ngot: %+v\nwant: %+v", got, want)
}
}
func TestChangesService_ListFilesReviewed(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?q=abc&reviewed=true"; got != want {
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want)
}
fmt.Fprint(w, `["/COMMIT_MSG","gerrit-server/RefControl.java"]`)
}))
defer ts.Close()
ctx := context.Background()
client := newClient(ctx, t, ts)
got, _, err := client.Changes.ListFilesReviewed(ctx, "123", "456", &gerrit.FilesOptions{
Q: "abc",
})
if err != nil {
t.Fatal(err)
}
want := []string{"/COMMIT_MSG", "gerrit-server/RefControl.java"}
if !reflect.DeepEqual(got, want) {
t.Errorf("client.Changes.ListFilesReviewed:\ngot: %q\nwant: %q", got, want)
}
}