2016-09-06 14:46:37 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
2016-09-08 23:44:25 -04:00
|
|
|
func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client {
|
|
|
|
return &http.Client{
|
|
|
|
Transport: transportFunc(doer),
|
2016-09-06 14:46:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func errorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) {
|
|
|
|
return func(req *http.Request) (*http.Response, error) {
|
|
|
|
header := http.Header{}
|
|
|
|
header.Set("Content-Type", "application/json")
|
|
|
|
|
|
|
|
body, err := json.Marshal(&types.ErrorResponse{
|
|
|
|
Message: message,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &http.Response{
|
|
|
|
StatusCode: statusCode,
|
|
|
|
Body: ioutil.NopCloser(bytes.NewReader(body)),
|
|
|
|
Header: header,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func plainTextErrorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) {
|
|
|
|
return func(req *http.Request) (*http.Response, error) {
|
|
|
|
return &http.Response{
|
|
|
|
StatusCode: statusCode,
|
|
|
|
Body: ioutil.NopCloser(bytes.NewReader([]byte(message))),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|