forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commits_test.go
52 lines (41 loc) · 1.62 KB
/
commits_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
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetCommitStatuses(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/repository/commits/b0b3a907f41409829b307a28b82fdbd552ee5a27/statuses", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1}]`)
})
opt := &GetCommitStatusesOptions{Ref: String("master"), Stage: String("test"), Name: String("ci/jenkins"), All: Bool(true)}
statuses, _, err := client.Commits.GetCommitStatuses("1", "b0b3a907f41409829b307a28b82fdbd552ee5a27", opt)
if err != nil {
t.Errorf("Commits.GetCommitStatuses returned error: %v", err)
}
want := []*CommitStatus{{ID: 1}}
if !reflect.DeepEqual(want, statuses) {
t.Errorf("Commits.GetCommitStatuses returned %+v, want %+v", statuses, want)
}
}
func TestSetCommitStatus(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/statuses/b0b3a907f41409829b307a28b82fdbd552ee5a27", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":1}`)
})
opt := &SetCommitStatusOptions{State: Running, Ref: String("master"), Name: String("ci/jenkins"), Context: String(""), TargetURL: String("http://abc"), Description: String("build")}
status, _, err := client.Commits.SetCommitStatus("1", "b0b3a907f41409829b307a28b82fdbd552ee5a27", opt)
if err != nil {
t.Errorf("Commits.SetCommitStatus returned error: %v", err)
}
want := &CommitStatus{ID: 1}
if !reflect.DeepEqual(want, status) {
t.Errorf("Commits.SetCommitStatus returned %+v, want %+v", status, want)
}
}