Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Jul 2, 2019
2 parents a175831 + 622510d commit 5837de7
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 783 deletions.
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 @@ -27,7 +26,6 @@ type Container interface {
ListServices(labels ...string) ([]swarm.Service, error)
ListTasks(namespace string) ([]swarm.Task, error)
Namespace(namespace 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
4 changes: 3 additions & 1 deletion 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, maxGraceTime
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("TestListServices"), services[0].Spec.Name)
}

func TestIntegrationServiceLogs(t *testing.T) {
c, err := New(nstestprefix)
require.NoError(t, err)
namespace := "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 @@ -252,30 +250,3 @@ func TestListServices(t *testing.T) {
}),
}, (<-dt.LastServiceList()).Options)
}

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

dt := dockertest.New()
c, _ := New(nstestprefix, 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

0 comments on commit 5837de7

Please sign in to comment.