Merge pull request #579 from thaJeztah/dont-trunc-on-quiet

Do not truncate ID on docker service ps --quiet
This commit is contained in:
Daniel Nephin 2017-10-02 10:33:23 -04:00 committed by GitHub
commit adfc2d17a0
3 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,7 @@ type fakeClient struct {
serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
serviceListFunc func(context.Context, types.ServiceListOptions) ([]swarm.Service, error)
taskListFunc func(context.Context, types.TaskListOptions) ([]swarm.Task, error)
infoFunc func(ctx context.Context) (types.Info, error)
}
@ -22,6 +23,9 @@ func (f *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions
}
func (f *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
if f.taskListFunc != nil {
return f.taskListFunc(ctx, options)
}
return nil, nil
}

View File

@ -69,6 +69,9 @@ func runPS(dockerCli command.Cli, options psOptions) error {
if len(format) == 0 {
format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
}
if options.quiet {
options.noTrunc = true
}
if err := task.Print(ctx, dockerCli, tasks, idresolver.New(client, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
return err
}

View File

@ -90,6 +90,22 @@ func TestRunPSWarnsOnNotFound(t *testing.T) {
assert.EqualError(t, err, "no such service: bar")
}
func TestRunPSQuiet(t *testing.T) {
client := &fakeClient{
serviceListFunc: func(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
return []swarm.Service{{ID: "foo"}}, nil
},
taskListFunc: func(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
return []swarm.Task{{ID: "sxabyp0obqokwekpun4rjo0b3"}}, nil
},
}
cli := test.NewFakeCli(client)
err := runPS(cli, psOptions{services: []string{"foo"}, quiet: true, filter: opts.NewFilterOpt()})
require.NoError(t, err)
assert.Equal(t, "sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String())
}
func TestUpdateNodeFilter(t *testing.T) {
selfNodeID := "foofoo"
filter := filters.NewArgs()