Skip to content

Commit

Permalink
cmd: check for all errors on log websockets (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
didil authored and bobheadxi committed Feb 7, 2019
1 parent 8e86582 commit 026ecae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func (c *Client) LogsWebSocket(container string, entries int) (SocketReader, err
if err == websocket.ErrBadHandshake {
return nil, fmt.Errorf("websocket handshake failed with status %d", resp.StatusCode)
}
if err != nil {
return nil, fmt.Errorf("failed to connect to daemon at %s: %s", url.Host, err.Error())
}
return socket, nil
}

Expand Down
11 changes: 11 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ func TestLogsWebsocket(t *testing.T) {
assert.Equal(t, []byte("hello world"), m)
}

func TestLogsWebsocketNoDaemon(t *testing.T) {
testServer := httptest.NewTLSServer(nil)
// close the server to test error
testServer.Close()

d := newMockClient(testServer)
_, err := d.LogsWebSocket("docker-compose", 10)
assert.Error(t, err)
assert.Contains(t, err.Error(), "connect: connection refused")
}

func TestUpdateEnv(t *testing.T) {
testServer := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit 026ecae

Please sign in to comment.