Merge pull request #245 from vdemeester/more-info-unit-tests

Add error unit tests for Info
This commit is contained in:
Antonio Murdaca 2016-06-01 13:51:05 +02:00
Родитель c15549e103 9b41a1b340
Коммит dbdcba0b66
1 изменённых файлов: 25 добавлений и 0 удалений

Просмотреть файл

@ -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{