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 89 90 91 92 93 94 95 96 97
|
package gitlab
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestListMergeStatusChecks(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/projects/1/merge_requests/1/status_checks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, exampleStatusChecks)
})
statusChecks, _, err := client.ExternalStatusChecks.ListMergeStatusChecks(1, 1, nil)
if err != nil {
t.Fatalf("ExternalStatusChecks.ListMergeStatusChecks returns an error: %v", err)
}
expectedStatusChecks := []*MergeStatusCheck{
{
ID: 2,
Name: "Rule 1",
ExternalURL: "https://gitlab.com/test-endpoint",
Status: "approved",
},
{
ID: 1,
Name: "Rule 2",
ExternalURL: "https://gitlab.com/test-endpoint-2",
Status: "pending",
},
}
assert.Equal(t, expectedStatusChecks, statusChecks)
}
func TestListProjectStatusChecks(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/projects/1/external_status_checks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, exampleProjectStatusChecks)
})
projectStatusChecks, _, err := client.ExternalStatusChecks.ListProjectStatusChecks(1, nil)
if err != nil {
t.Fatalf("ExternalStatusChecks.ListProjectStatusChecks returns an error: %v", err)
}
time1, err := time.Parse(time.RFC3339, "2020-10-12T14:04:50.787Z")
if err != nil {
t.Errorf("ExternalStatusChecks.ListProjectStatusChecks returns an error: %v", err)
}
expectedProjectStatusChecks := []*ProjectStatusCheck{
{
ID: 1,
Name: "Compliance Check",
ProjectID: 6,
ExternalURL: "https://gitlab.com/example/test.json",
ProtectedBranches: []StatusCheckProtectedBranch{
{
ID: 14,
ProjectID: 6,
Name: "master",
CreatedAt: &time1,
UpdatedAt: &time1,
CodeOwnerApprovalRequired: false,
},
},
},
}
assert.Equal(t, expectedProjectStatusChecks, projectStatusChecks)
}
func TestRetryFailedStatusCheckForAMergeRequest(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/projects/1/merge_requests/2/status_checks/3/retry", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"message": "202 Accepted"}`)
})
resp, err := client.ExternalStatusChecks.RetryFailedStatusCheckForAMergeRequest(1, 2, 3)
if err != nil {
t.Fatalf("ExternalStatusChecks.RetryFailedStatusCheckForAMergeRequest returns an error: %v", err)
}
assert.NotNil(t, resp)
}
|