-
-
Notifications
You must be signed in to change notification settings - Fork 398
/
gitlab_mr_diff_test.go
52 lines (46 loc) 路 1.35 KB
/
gitlab_mr_diff_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 (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/xanzy/go-gitlab"
)
func TestGitLabMergeRequestDiff_Diff(t *testing.T) {
getMRAPICall := 0
getBranchAPICall := 0
mux := http.NewServeMux()
mux.HandleFunc("/api/v4/projects/o/r/merge_requests/14", func(w http.ResponseWriter, r *http.Request) {
getMRAPICall++
if r.Method != http.MethodGet {
t.Errorf("unexpected access: %v %v", r.Method, r.URL)
}
w.Write([]byte(`{"target_project_id": 14, "target_branch": "test-branch"}`))
})
mux.HandleFunc("/api/v4/projects/14/repository/branches/test-branch", func(w http.ResponseWriter, r *http.Request) {
getBranchAPICall++
if r.Method != http.MethodGet {
t.Errorf("unexpected access: %v %v", r.Method, r.URL)
}
w.Write([]byte(`{"commit": {"id": "HEAD~"}}`))
})
ts := httptest.NewServer(mux)
defer ts.Close()
cli, err := gitlab.NewClient("", gitlab.WithBaseURL(ts.URL+"/api/v4"))
if err != nil {
t.Fatal(err)
}
g, err := NewGitLabMergeRequestDiff(cli, "o", "r", 14, "HEAD")
if err != nil {
t.Fatal(err)
}
if _, err := g.Diff(context.Background()); err != nil {
t.Fatal(err)
}
if getMRAPICall != 1 {
t.Errorf("Get GitLab MergeRequest API called %v times, want once", getMRAPICall)
}
if getBranchAPICall != 1 {
t.Errorf("Get GitLab Branch API called %v times, want once", getBranchAPICall)
}
}