mirror of https://github.com/kubernetes/kops.git
41 lines
927 B
Go
41 lines
927 B
Go
package client
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/docker/engine-api/types"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func TestContainerLogsError(t *testing.T) {
|
|
client := &Client{
|
|
transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")),
|
|
}
|
|
_, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{})
|
|
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
|
t.Fatalf("expected a Server Error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func ExampleClient_ContainerLogs_withTimeout() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
client, _ := NewEnvClient()
|
|
reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
_, err = io.Copy(os.Stdout, reader)
|
|
if err != nil && err != io.EOF {
|
|
log.Fatal(err)
|
|
}
|
|
}
|