forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployments_merge_requests_test.go
51 lines (42 loc) · 1.77 KB
/
deployments_merge_requests_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
package gitlab
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDeploymentMergeRequestsService_ListDeploymentMergeRequests(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v4/projects/278964/deployments/2/merge_requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testParams(t, r, "assignee_id=Any&with_labels_details=true&with_merge_status_recheck=true")
mustWriteHTTPResponse(t, w, "testdata/get_merge_requests.json")
})
opts := ListMergeRequestsOptions{
AssigneeID: AssigneeID(UserIDAny),
WithLabelsDetails: Bool(true),
WithMergeStatusRecheck: Bool(true),
}
mergeRequests, _, err := client.DeploymentMergeRequests.ListDeploymentMergeRequests(278964, 2, &opts)
require.NoError(t, err)
require.Equal(t, 20, len(mergeRequests))
validStates := []string{"opened", "closed", "locked", "merged"}
mergeStatuses := []string{"can_be_merged", "cannot_be_merged"}
allCreatedBefore := time.Date(2019, 8, 21, 0, 0, 0, 0, time.UTC)
allCreatedAfter := time.Date(2019, 8, 17, 0, 0, 0, 0, time.UTC)
for _, mr := range mergeRequests {
require.Equal(t, 278964, mr.ProjectID)
require.Contains(t, validStates, mr.State)
assert.Less(t, mr.CreatedAt.Unix(), allCreatedBefore.Unix())
assert.Greater(t, mr.CreatedAt.Unix(), allCreatedAfter.Unix())
assert.LessOrEqual(t, mr.CreatedAt.Unix(), mr.UpdatedAt.Unix())
assert.LessOrEqual(t, mr.TaskCompletionStatus.CompletedCount, mr.TaskCompletionStatus.Count)
require.Contains(t, mergeStatuses, mr.MergeStatus)
// list requests do not provide these fields:
assert.Nil(t, mr.Pipeline)
assert.Nil(t, mr.HeadPipeline)
assert.Equal(t, "", mr.DiffRefs.HeadSha)
}
}