-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from ripcurld0/nat_sort_service
Sort services names in a natural order
- Loading branch information
Showing
5 changed files
with
82 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/swarm" | ||
"github.com/docker/docker/client" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type fakeClient struct { | ||
client.Client | ||
serviceListFunc func(context.Context, types.ServiceListOptions) ([]swarm.Service, error) | ||
} | ||
|
||
func (f *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { | ||
if f.serviceListFunc != nil { | ||
return f.serviceListFunc(ctx, options) | ||
} | ||
return nil, nil | ||
} | ||
|
||
func (f *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (f *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) { | ||
return nil, nil | ||
} | ||
|
||
func newService(id string, name string) swarm.Service { | ||
return swarm.Service{ | ||
ID: id, | ||
Spec: swarm.ServiceSpec{Annotations: swarm.Annotations{Name: name}}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/net/context" | ||
|
||
"github.com/docker/cli/cli/internal/test" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/swarm" | ||
"github.com/docker/docker/pkg/testutil" | ||
"github.com/docker/docker/pkg/testutil/golden" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestServiceListOrder(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{ | ||
serviceListFunc: func(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { | ||
return []swarm.Service{ | ||
newService("a57dbe8", "service-1-foo"), | ||
newService("a57dbdd", "service-10-foo"), | ||
newService("aaaaaaa", "service-2-foo"), | ||
}, nil | ||
}, | ||
}) | ||
cmd := newListCommand(cli) | ||
cmd.Flags().Set("format", "{{.Name}}") | ||
assert.NoError(t, cmd.Execute()) | ||
actual := cli.OutBuffer().String() | ||
expected := golden.Get(t, []byte(actual), "service-list-sort.golden") | ||
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
service-1-foo | ||
service-2-foo | ||
service-10-foo |