Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove service logs api #1153

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package container
import (
"context"
"errors"
"io"
"time"

"github.com/docker/docker/api/types"
Expand All @@ -28,7 +27,6 @@ type Container interface {
ListServices(labels ...string) ([]swarm.Service, error)
ListTasks(namespace []string) ([]swarm.Task, error)
Namespace(ss []string) string
ServiceLogs(namespace []string) (io.ReadCloser, error)
SharedNetworkID() (networkID string, err error)
StartService(options ServiceOptions) (serviceID string, err error)
Status(namespace []string) (StatusType, error)
Expand Down
16 changes: 0 additions & 16 deletions container/dockertest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type requests struct {
serviceList chan ServiceListRequest
serviceInspectWithRaw chan ServiceInspectWithRawRequest
serviceRemove chan ServiceRemoveRequest
serviceLogs chan ServiceLogsRequest
events chan EventsRequest
}

Expand All @@ -62,7 +61,6 @@ type responses struct {
serviceList chan serviceListResponse
serviceInspectWithRaw chan serviceInspectWithRawResponse
serviceRemove chan serviceRemoveResponse
serviceLogs chan serviceLogsResponse
containerInspect chan containerInspectResponse
containerList chan containerListResponse
containerStop chan containerStopResponse
Expand Down Expand Up @@ -92,7 +90,6 @@ func newClient() *Client {
serviceList: make(chan ServiceListRequest, 20),
serviceInspectWithRaw: make(chan ServiceInspectWithRawRequest, 20),
serviceRemove: make(chan ServiceRemoveRequest, 20),
serviceLogs: make(chan ServiceLogsRequest, 20),
events: make(chan EventsRequest, 20),
},

Expand All @@ -108,7 +105,6 @@ func newClient() *Client {
serviceList: make(chan serviceListResponse, 20),
serviceInspectWithRaw: make(chan serviceInspectWithRawResponse, 20),
serviceRemove: make(chan serviceRemoveResponse, 20),
serviceLogs: make(chan serviceLogsResponse, 20),
containerInspect: make(chan containerInspectResponse, 20),
containerList: make(chan containerListResponse, 20),
containerStop: make(chan containerStopResponse, 20),
Expand Down Expand Up @@ -291,18 +287,6 @@ func (c *Client) ServiceRemove(ctx context.Context, serviceID string) error {
}
}

// ServiceLogs is the mock version of the actual method.
func (c *Client) ServiceLogs(ctx context.Context,
serviceID string, options types.ContainerLogsOptions) (io.ReadCloser, error) {
c.requests.serviceLogs <- ServiceLogsRequest{serviceID, options}
select {
case resp := <-c.responses.serviceLogs:
return resp.rc, resp.err
default:
return nil, nil
}
}

// Events is the mock version of the actual method.
func (c *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) {
c.requests.events <- EventsRequest{Options: options}
Expand Down
6 changes: 0 additions & 6 deletions container/dockertest/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ type ServiceInspectWithRawRequest struct {
Options types.ServiceInspectOptions
}

// ServiceLogsRequest holds call arguments of *Client.ServiceLogs.
type ServiceLogsRequest struct {
ServiceID string
Options types.ContainerLogsOptions
}

// NegotiateAPIVersionRequest holds call arguments of *Client.NegotiateAPIVersion.
type NegotiateAPIVersionRequest struct {
}
Expand Down
8 changes: 0 additions & 8 deletions container/dockertest/responses.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package dockertest

import (
"io"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/swarm"
)

// serviceLogsResponse holds fake return values of *Client.ServiceLogs.
type serviceLogsResponse struct {
rc io.ReadCloser
err error
}

// serviceRemoveResponse holds fake return values of *Client.ServiceRemove.
type serviceRemoveResponse struct {
err error
Expand Down
10 changes: 0 additions & 10 deletions container/dockertest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ func (t *Testing) ProvideServiceInspectWithRaw(service swarm.Service, data []byt
t.client.responses.serviceInspectWithRaw <- serviceInspectWithRawResponse{service, data, err}
}

// ProvideServiceLogs sets fake return values for the next call to *Client.ServiceLogs.
func (t *Testing) ProvideServiceLogs(rc io.ReadCloser, err error) {
t.client.responses.serviceLogs <- serviceLogsResponse{rc, err}
}

// ProvideTaskList sets fake return values for the next call to *Client.TaskList.
func (t *Testing) ProvideTaskList(tasks []swarm.Task, err error) {
t.client.responses.taskList <- taskListResponse{tasks, err}
Expand Down Expand Up @@ -192,11 +187,6 @@ func (t *Testing) LastServiceRemove() <-chan ServiceRemoveRequest {
return t.client.requests.serviceRemove
}

// LastServiceLogs returns a channel that receives call arguments of last *Client.ServiceLogs call.
func (t *Testing) LastServiceLogs() <-chan ServiceLogsRequest {
return t.client.requests.serviceLogs
}

// LastEvents returns a channel that receives call arguments of last *Client.ServiceLogs call.
func (t *Testing) LastEvents() <-chan EventsRequest {
return t.client.requests.events
Expand Down
21 changes: 0 additions & 21 deletions container/dockertest/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,6 @@ func TestServiceRemove(t *testing.T) {
require.Equal(t, serviceID, ll.ServiceID)
}

func TestServiceLogs(t *testing.T) {
serviceID := "1"
data := []byte{1, 2}
options := types.ContainerLogsOptions{ShowStdout: true}

dt := New()
dt.ProvideServiceLogs(ioutil.NopCloser(bytes.NewReader(data)), errGeneric)

rc, err := dt.Client().ServiceLogs(context.Background(), serviceID, options)
require.Equal(t, errGeneric, err)
defer rc.Close()

data1, err := ioutil.ReadAll(rc)
require.NoError(t, err)
require.Equal(t, data, data1)

ll := <-dt.LastServiceLogs()
require.Equal(t, serviceID, ll.ServiceID)
require.Equal(t, options, ll.Options)
}

func TestEvents(t *testing.T) {
dt := New()
msgC := make(chan events.Message)
Expand Down
24 changes: 0 additions & 24 deletions container/mocks/Container.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions container/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package container

import (
"context"
"io"
"time"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -106,15 +105,3 @@ func (c *DockerContainer) deletePendingContainer(namespace []string, maxGraceTim
time.Sleep(1 * time.Second)
return c.deletePendingContainer(namespace, maxGraceTime)
}

// ServiceLogs returns the logs of a service.
func (c *DockerContainer) ServiceLogs(namespace []string) (io.ReadCloser, error) {
return c.client.ServiceLogs(context.Background(), c.Namespace(namespace),
types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Timestamps: false,
Follow: true,
},
)
}
11 changes: 0 additions & 11 deletions container/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,3 @@ func TestIntegrationListServices(t *testing.T) {
require.Equal(t, 1, len(services))
require.Equal(t, c.Namespace([]string{"TestListServices"}), services[0].Spec.Name)
}

func TestIntegrationServiceLogs(t *testing.T) {
c, err := New()
require.NoError(t, err)
namespace := []string{"TestServiceLogs"}
startTestService(namespace)
defer c.StopService(namespace)
reader, err := c.ServiceLogs(namespace)
require.NoError(t, err)
require.NotNil(t, reader)
}
29 changes: 0 additions & 29 deletions container/service_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package container

import (
"bytes"
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -253,30 +251,3 @@ func TestListServices(t *testing.T) {
}),
}, (<-dt.LastServiceList()).Options)
}

func TestServiceLogs(t *testing.T) {
namespace := []string{"namespace"}
data := []byte{1, 2}

dt := dockertest.New()
c, _ := New(ClientOption(dt.Client()))

dt.ProvideServiceLogs(ioutil.NopCloser(bytes.NewReader(data)), nil)

reader, err := c.ServiceLogs(namespace)
require.NoError(t, err)
defer reader.Close()

bytes, err := ioutil.ReadAll(reader)
require.NoError(t, err)
require.Equal(t, data, bytes)

ll := <-dt.LastServiceLogs()
require.Equal(t, c.Namespace(namespace), ll.ServiceID)
require.Equal(t, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Timestamps: false,
Follow: true,
}, ll.Options)
}
Loading