代码拉取完成,页面将自动刷新
package main
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func startWorkhorseServerWithLongPolling(authBackend string, pollingDuration time.Duration) *httptest.Server {
uc := newUpstreamConfig(authBackend)
uc.APICILongPollingDuration = pollingDuration
return startWorkhorseServerWithConfig(uc)
}
type requestJobFunction func(url string, body io.Reader) (*http.Response, error)
func requestJobV1(url string, body io.Reader) (*http.Response, error) {
resource := `/ci/api/v1/builds/register.json`
return http.Post(url+resource, `application/json`, body)
}
func requestJobV4(url string, body io.Reader) (*http.Response, error) {
resource := `/api/v4/jobs/request`
return http.Post(url+resource, `application/json`, body)
}
func testJobsLongPolling(t *testing.T, pollingDuration time.Duration, requestJob requestJobFunction) *http.Response {
ws := startWorkhorseServerWithLongPolling("http://localhost/", pollingDuration)
defer ws.Close()
resp, err := requestJob(ws.URL, nil)
assert.NoError(t, err)
defer resp.Body.Close()
return resp
}
func testJobsLongPollingEndpointDisabled(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, 0, requestJob)
assert.NotEqual(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
}
func testJobsLongPollingEndpoint(t *testing.T, requestJob requestJobFunction) {
resp := testJobsLongPolling(t, time.Minute, requestJob)
assert.Equal(t, "yes", resp.Header.Get("Gitlab-Ci-Builds-Polling"))
}
func TestJobsLongPollingEndpointDisabled(t *testing.T) {
testJobsLongPollingEndpointDisabled(t, requestJobV1)
testJobsLongPollingEndpointDisabled(t, requestJobV4)
}
func TestJobsLongPollingEndpoint(t *testing.T) {
testJobsLongPollingEndpoint(t, requestJobV1)
testJobsLongPollingEndpoint(t, requestJobV4)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。