forked from jenkins-zh/jenkins-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore_test_common.go
34 lines (30 loc) · 1.02 KB
/
core_test_common.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
package client
import (
"bytes"
"fmt"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
"io/ioutil"
"net/http"
)
// PrepareRestart only for test
func PrepareRestart(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string, statusCode int) {
request, _ := http.NewRequest("POST", fmt.Sprintf("%s/safeRestart", rootURL), nil)
response := PrepareCommonPost(request, "", roundTripper, user, password, rootURL)
response.StatusCode = statusCode
return
}
// PrepareForGetIdentity only for test
func PrepareForGetIdentity(roundTripper *mhttp.MockRoundTripper, rootURL, user, password string) {
request, _ := http.NewRequest("GET", fmt.Sprintf("%s/instance", rootURL), nil)
response := &http.Response{
StatusCode: 200,
Request: request,
Body: ioutil.NopCloser(bytes.NewBufferString(`
{"fingerprint":"fingerprint","publicKey":"publicKey","systemMessage":"systemMessage"}`)),
}
roundTripper.EXPECT().
RoundTrip(request).Return(response, nil)
if user != "" && password != "" {
request.SetBasicAuth(user, password)
}
}