зеркало из https://github.com/docker/engine-api.git
Merge pull request #245 from vdemeester/more-info-unit-tests
Add error unit tests for Info
This commit is contained in:
Коммит
dbdcba0b66
|
@ -13,6 +13,31 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestInfoServerError(t *testing.T) {
|
||||||
|
client := &Client{
|
||||||
|
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
||||||
|
}
|
||||||
|
_, err := client.Info(context.Background())
|
||||||
|
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||||
|
t.Fatalf("expected a Server Error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInfoInvalidResponseJSONError(t *testing.T) {
|
||||||
|
client := &Client{
|
||||||
|
transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
Body: ioutil.NopCloser(bytes.NewReader([]byte("invalid json"))),
|
||||||
|
}, nil
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
_, err := client.Info(context.Background())
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "invalid character") {
|
||||||
|
t.Fatalf("expected a 'invalid character' error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInfo(t *testing.T) {
|
func TestInfo(t *testing.T) {
|
||||||
expectedURL := "/info"
|
expectedURL := "/info"
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче