mirror of https://github.com/docker/cli.git
Merge pull request #5222 from thaJeztah/cleanup_for_engine_update
assorted minor changes in preparation of updating docker/docker dependency
This commit is contained in:
commit
3837aa62d8
|
@ -32,10 +32,13 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
||||||
args: []string{"5cb5bb5e4a3b"},
|
args: []string{"5cb5bb5e4a3b"},
|
||||||
expectedError: "You cannot attach to a stopped container",
|
expectedError: "You cannot attach to a stopped container",
|
||||||
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
||||||
c := types.ContainerJSON{}
|
return types.ContainerJSON{
|
||||||
c.ContainerJSONBase = &types.ContainerJSONBase{}
|
ContainerJSONBase: &types.ContainerJSONBase{
|
||||||
c.ContainerJSONBase.State = &types.ContainerState{Running: false}
|
State: &types.ContainerState{
|
||||||
return c, nil
|
Running: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -43,13 +46,14 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
||||||
args: []string{"5cb5bb5e4a3b"},
|
args: []string{"5cb5bb5e4a3b"},
|
||||||
expectedError: "You cannot attach to a paused container",
|
expectedError: "You cannot attach to a paused container",
|
||||||
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
||||||
c := types.ContainerJSON{}
|
return types.ContainerJSON{
|
||||||
c.ContainerJSONBase = &types.ContainerJSONBase{}
|
ContainerJSONBase: &types.ContainerJSONBase{
|
||||||
c.ContainerJSONBase.State = &types.ContainerState{
|
State: &types.ContainerState{
|
||||||
Running: true,
|
Running: true,
|
||||||
Paused: true,
|
Paused: true,
|
||||||
}
|
},
|
||||||
return c, nil
|
},
|
||||||
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -57,14 +61,15 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
||||||
args: []string{"5cb5bb5e4a3b"},
|
args: []string{"5cb5bb5e4a3b"},
|
||||||
expectedError: "You cannot attach to a restarting container",
|
expectedError: "You cannot attach to a restarting container",
|
||||||
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
containerInspectFunc: func(containerID string) (types.ContainerJSON, error) {
|
||||||
c := types.ContainerJSON{}
|
return types.ContainerJSON{
|
||||||
c.ContainerJSONBase = &types.ContainerJSONBase{}
|
ContainerJSONBase: &types.ContainerJSONBase{
|
||||||
c.ContainerJSONBase.State = &types.ContainerState{
|
State: &types.ContainerState{
|
||||||
Running: true,
|
Running: true,
|
||||||
Paused: false,
|
Paused: false,
|
||||||
Restarting: true,
|
Restarting: true,
|
||||||
}
|
},
|
||||||
return c, nil
|
},
|
||||||
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"aliases": "docker container pause, docker pause",
|
"aliases": "docker container pause, docker pause",
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool {
|
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
|
||||||
return container.State != "paused"
|
return ctr.State != "paused"
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,12 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error {
|
func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error {
|
||||||
var errs []string
|
var errs []string
|
||||||
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause)
|
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause)
|
||||||
for _, container := range opts.containers {
|
for _, ctr := range opts.containers {
|
||||||
if err := <-errChan; err != nil {
|
if err := <-errChan; err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), container)
|
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errors.New(strings.Join(errs, "\n"))
|
return errors.New(strings.Join(errs, "\n"))
|
||||||
|
|
|
@ -43,8 +43,8 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"aliases": "docker container start, docker start",
|
"aliases": "docker container start, docker start",
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(container types.Container) bool {
|
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool {
|
||||||
return container.State == "exited" || container.State == "created"
|
return ctr.State == "exited" || ctr.State == "created"
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"aliases": "docker container unpause, docker unpause",
|
"aliases": "docker container unpause, docker unpause",
|
||||||
},
|
},
|
||||||
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool {
|
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
|
||||||
return container.State == "paused"
|
return ctr.State == "paused"
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -42,12 +42,12 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error {
|
func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error {
|
||||||
var errs []string
|
var errs []string
|
||||||
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
|
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
|
||||||
for _, container := range opts.containers {
|
for _, ctr := range opts.containers {
|
||||||
if err := <-errChan; err != nil {
|
if err := <-errChan; err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), container)
|
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errors.New(strings.Join(errs, "\n"))
|
return errors.New(strings.Join(errs, "\n"))
|
||||||
|
|
|
@ -130,17 +130,17 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
|
||||||
warns []string
|
warns []string
|
||||||
errs []string
|
errs []string
|
||||||
)
|
)
|
||||||
for _, container := range options.containers {
|
for _, ctr := range options.containers {
|
||||||
r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig)
|
r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(dockerCli.Out(), container)
|
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
|
||||||
}
|
}
|
||||||
warns = append(warns, r.Warnings...)
|
warns = append(warns, r.Warnings...)
|
||||||
}
|
}
|
||||||
if len(warns) > 0 {
|
if len(warns) > 0 {
|
||||||
fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
|
_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
return errors.New(strings.Join(errs, "\n"))
|
return errors.New(strings.Join(errs, "\n"))
|
||||||
|
|
|
@ -39,12 +39,12 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
|
|
||||||
func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error {
|
func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error {
|
||||||
var errs []string
|
var errs []string
|
||||||
for _, container := range opts.containers {
|
for _, ctr := range opts.containers {
|
||||||
resultC, errC := dockerCli.Client().ContainerWait(ctx, container, "")
|
resultC, errC := dockerCli.Client().ContainerWait(ctx, ctr, "")
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case result := <-resultC:
|
case result := <-resultC:
|
||||||
fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
|
_, _ = fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
|
||||||
case err := <-errC:
|
case err := <-errC:
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,8 @@ ports: {{- pad .Ports 1 0}}
|
||||||
// ContainerWrite renders the context for a list of containers
|
// ContainerWrite renders the context for a list of containers
|
||||||
func ContainerWrite(ctx Context, containers []types.Container) error {
|
func ContainerWrite(ctx Context, containers []types.Container) error {
|
||||||
render := func(format func(subContext SubContext) error) error {
|
render := func(format func(subContext SubContext) error) error {
|
||||||
for _, container := range containers {
|
for _, ctr := range containers {
|
||||||
err := format(&ContainerContext{trunc: ctx.Trunc, c: container})
|
err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,66 +30,155 @@ func TestContainerPsContext(t *testing.T) {
|
||||||
expValue string
|
expValue string
|
||||||
call func() string
|
call func() string
|
||||||
}{
|
}{
|
||||||
{types.Container{ID: containerID}, true, stringid.TruncateID(containerID), ctx.ID},
|
|
||||||
{types.Container{ID: containerID}, false, containerID, ctx.ID},
|
|
||||||
{types.Container{Names: []string{"/foobar_baz"}}, true, "foobar_baz", ctx.Names},
|
|
||||||
{types.Container{Image: "ubuntu"}, true, "ubuntu", ctx.Image},
|
|
||||||
{types.Container{Image: "verylongimagename"}, true, "verylongimagename", ctx.Image},
|
|
||||||
{types.Container{Image: "verylongimagename"}, false, "verylongimagename", ctx.Image},
|
|
||||||
{
|
{
|
||||||
types.Container{
|
container: types.Container{ID: containerID},
|
||||||
|
trunc: true,
|
||||||
|
expValue: stringid.TruncateID(containerID),
|
||||||
|
call: ctx.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{ID: containerID},
|
||||||
|
expValue: containerID,
|
||||||
|
call: ctx.ID,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Names: []string{"/foobar_baz"}},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "foobar_baz",
|
||||||
|
call: ctx.Names,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Image: "ubuntu"},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "ubuntu",
|
||||||
|
call: ctx.Image,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Image: "verylongimagename"},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "verylongimagename",
|
||||||
|
call: ctx.Image,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Image: "verylongimagename"},
|
||||||
|
expValue: "verylongimagename",
|
||||||
|
call: ctx.Image,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{
|
||||||
Image: "a5a665ff33eced1e0803148700880edab4",
|
Image: "a5a665ff33eced1e0803148700880edab4",
|
||||||
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
|
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
|
||||||
},
|
},
|
||||||
true,
|
trunc: true,
|
||||||
"a5a665ff33ec",
|
expValue: "a5a665ff33ec",
|
||||||
ctx.Image,
|
call: ctx.Image,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
types.Container{
|
container: types.Container{
|
||||||
Image: "a5a665ff33eced1e0803148700880edab4",
|
Image: "a5a665ff33eced1e0803148700880edab4",
|
||||||
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
|
ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5",
|
||||||
},
|
},
|
||||||
false,
|
expValue: "a5a665ff33eced1e0803148700880edab4",
|
||||||
"a5a665ff33eced1e0803148700880edab4",
|
call: ctx.Image,
|
||||||
ctx.Image,
|
|
||||||
},
|
},
|
||||||
{types.Container{Image: ""}, true, "<no image>", ctx.Image},
|
{
|
||||||
{types.Container{Command: "sh -c 'ls -la'"}, true, `"sh -c 'ls -la'"`, ctx.Command},
|
container: types.Container{Image: ""},
|
||||||
{types.Container{Created: unix}, true, time.Unix(unix, 0).String(), ctx.CreatedAt},
|
trunc: true,
|
||||||
{types.Container{Ports: []types.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, true, "8080/tcp", ctx.Ports},
|
expValue: "<no image>",
|
||||||
{types.Container{Status: "RUNNING"}, true, "RUNNING", ctx.Status},
|
call: ctx.Image,
|
||||||
{types.Container{SizeRw: 10}, true, "10B", ctx.Size},
|
},
|
||||||
{types.Container{SizeRw: 10, SizeRootFs: 20}, true, "10B (virtual 20B)", ctx.Size},
|
{
|
||||||
{types.Container{}, true, "", ctx.Labels},
|
container: types.Container{Command: "sh -c 'ls -la'"},
|
||||||
{types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, true, "cpu=6,storage=ssd", ctx.Labels},
|
trunc: true,
|
||||||
{types.Container{Created: unix}, true, "About a minute ago", ctx.RunningFor},
|
expValue: `"sh -c 'ls -la'"`,
|
||||||
{types.Container{
|
call: ctx.Command,
|
||||||
Mounts: []types.MountPoint{
|
},
|
||||||
{
|
{
|
||||||
Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set",
|
container: types.Container{Created: unix},
|
||||||
Driver: "local",
|
trunc: true,
|
||||||
Source: "/a/path",
|
expValue: time.Unix(unix, 0).String(),
|
||||||
|
call: ctx.CreatedAt,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Ports: []types.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "8080/tcp",
|
||||||
|
call: ctx.Ports,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Status: "RUNNING"},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "RUNNING",
|
||||||
|
call: ctx.Status,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{SizeRw: 10},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "10B",
|
||||||
|
call: ctx.Size,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{SizeRw: 10, SizeRootFs: 20},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "10B (virtual 20B)",
|
||||||
|
call: ctx.Size,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{},
|
||||||
|
trunc: true,
|
||||||
|
call: ctx.Labels,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "cpu=6,storage=ssd",
|
||||||
|
call: ctx.Labels,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{Created: unix},
|
||||||
|
trunc: true,
|
||||||
|
expValue: "About a minute ago",
|
||||||
|
call: ctx.RunningFor,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: types.Container{
|
||||||
|
Mounts: []types.MountPoint{
|
||||||
|
{
|
||||||
|
Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set",
|
||||||
|
Driver: "local",
|
||||||
|
Source: "/a/path",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, true, "this-is-a-long…", ctx.Mounts},
|
trunc: true,
|
||||||
{types.Container{
|
expValue: "this-is-a-long…",
|
||||||
Mounts: []types.MountPoint{
|
call: ctx.Mounts,
|
||||||
{
|
},
|
||||||
Driver: "local",
|
{
|
||||||
Source: "/a/path",
|
container: types.Container{
|
||||||
|
Mounts: []types.MountPoint{
|
||||||
|
{
|
||||||
|
Driver: "local",
|
||||||
|
Source: "/a/path",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, false, "/a/path", ctx.Mounts},
|
expValue: "/a/path",
|
||||||
{types.Container{
|
call: ctx.Mounts,
|
||||||
Mounts: []types.MountPoint{
|
},
|
||||||
{
|
{
|
||||||
Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203",
|
container: types.Container{
|
||||||
Driver: "local",
|
Mounts: []types.MountPoint{
|
||||||
Source: "/a/path",
|
{
|
||||||
|
Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203",
|
||||||
|
Driver: "local",
|
||||||
|
Source: "/a/path",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, false, "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203", ctx.Mounts},
|
expValue: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203",
|
||||||
|
call: ctx.Mounts,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
@ -134,52 +223,52 @@ func TestContainerContextWrite(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
Context{Format: "{{InvalidFunction}}"},
|
context: Context{Format: "{{InvalidFunction}}"},
|
||||||
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
expected: `template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: "{{nil}}"},
|
context: Context{Format: "{{nil}}"},
|
||||||
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table", false, true)},
|
context: Context{Format: NewContainerFormat("table", false, true)},
|
||||||
`CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
|
expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
|
||||||
containerID1 ubuntu "" 24 hours ago foobar_baz 0B
|
containerID1 ubuntu "" 24 hours ago foobar_baz 0B
|
||||||
containerID2 ubuntu "" 24 hours ago foobar_bar 0B
|
containerID2 ubuntu "" 24 hours ago foobar_bar 0B
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table", false, false)},
|
context: Context{Format: NewContainerFormat("table", false, false)},
|
||||||
`CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
containerID1 ubuntu "" 24 hours ago foobar_baz
|
containerID1 ubuntu "" 24 hours ago foobar_baz
|
||||||
containerID2 ubuntu "" 24 hours ago foobar_bar
|
containerID2 ubuntu "" 24 hours ago foobar_bar
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table {{.Image}}", false, false)},
|
context: Context{Format: NewContainerFormat("table {{.Image}}", false, false)},
|
||||||
"IMAGE\nubuntu\nubuntu\n",
|
expected: "IMAGE\nubuntu\nubuntu\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table {{.Image}}", false, true)},
|
context: Context{Format: NewContainerFormat("table {{.Image}}", false, true)},
|
||||||
"IMAGE\nubuntu\nubuntu\n",
|
expected: "IMAGE\nubuntu\nubuntu\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
|
context: Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
|
||||||
"containerID1\ncontainerID2\n",
|
expected: "containerID1\ncontainerID2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table", true, false)},
|
context: Context{Format: NewContainerFormat("table", true, false)},
|
||||||
"containerID1\ncontainerID2\n",
|
expected: "containerID1\ncontainerID2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table {{.State}}", false, true)},
|
context: Context{Format: NewContainerFormat("table {{.State}}", false, true)},
|
||||||
"STATE\nrunning\nrunning\n",
|
expected: "STATE\nrunning\nrunning\n",
|
||||||
},
|
},
|
||||||
// Raw Format
|
// Raw Format
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("raw", false, false)},
|
context: Context{Format: NewContainerFormat("raw", false, false)},
|
||||||
fmt.Sprintf(`container_id: containerID1
|
expected: fmt.Sprintf(`container_id: containerID1
|
||||||
image: ubuntu
|
image: ubuntu
|
||||||
command: ""
|
command: ""
|
||||||
created_at: %s
|
created_at: %s
|
||||||
|
@ -202,8 +291,8 @@ ports:
|
||||||
`, expectedTime, expectedTime),
|
`, expectedTime, expectedTime),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("raw", false, true)},
|
context: Context{Format: NewContainerFormat("raw", false, true)},
|
||||||
fmt.Sprintf(`container_id: containerID1
|
expected: fmt.Sprintf(`container_id: containerID1
|
||||||
image: ubuntu
|
image: ubuntu
|
||||||
command: ""
|
command: ""
|
||||||
created_at: %s
|
created_at: %s
|
||||||
|
@ -228,26 +317,26 @@ size: 0B
|
||||||
`, expectedTime, expectedTime),
|
`, expectedTime, expectedTime),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("raw", true, false)},
|
context: Context{Format: NewContainerFormat("raw", true, false)},
|
||||||
"container_id: containerID1\ncontainer_id: containerID2\n",
|
expected: "container_id: containerID1\ncontainer_id: containerID2\n",
|
||||||
},
|
},
|
||||||
// Custom Format
|
// Custom Format
|
||||||
{
|
{
|
||||||
Context{Format: "{{.Image}}"},
|
context: Context{Format: "{{.Image}}"},
|
||||||
"ubuntu\nubuntu\n",
|
expected: "ubuntu\nubuntu\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("{{.Image}}", false, true)},
|
context: Context{Format: NewContainerFormat("{{.Image}}", false, true)},
|
||||||
"ubuntu\nubuntu\n",
|
expected: "ubuntu\nubuntu\n",
|
||||||
},
|
},
|
||||||
// Special headers for customized table format
|
// Special headers for customized table format
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)},
|
context: Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)},
|
||||||
string(golden.Get(t, "container-context-write-special-headers.golden")),
|
expected: string(golden.Get(t, "container-context-write-special-headers.golden")),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat(`table {{split .Image ":"}}`, false, false)},
|
context: Context{Format: NewContainerFormat(`table {{split .Image ":"}}`, false, false)},
|
||||||
"IMAGE\n[ubuntu]\n[ubuntu]\n",
|
expected: "IMAGE\n[ubuntu]\n[ubuntu]\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,46 +369,44 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: "{{.Image}}",
|
Format: "{{.Image}}",
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: "table {{.Image}}",
|
Format: "table {{.Image}}",
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"IMAGE\n",
|
expected: "IMAGE\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: NewContainerFormat("{{.Image}}", false, true),
|
Format: NewContainerFormat("{{.Image}}", false, true),
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: NewContainerFormat("table {{.Image}}", false, true),
|
Format: NewContainerFormat("table {{.Image}}", false, true),
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"IMAGE\n",
|
expected: "IMAGE\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: "table {{.Image}}\t{{.Size}}",
|
Format: "table {{.Image}}\t{{.Size}}",
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"IMAGE SIZE\n",
|
expected: "IMAGE SIZE\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{
|
context: Context{
|
||||||
Format: NewContainerFormat("table {{.Image}}\t{{.Size}}", false, true),
|
Format: NewContainerFormat("table {{.Image}}\t{{.Size}}", false, true),
|
||||||
Output: out,
|
Output: out,
|
||||||
},
|
},
|
||||||
"IMAGE SIZE\n",
|
expected: "IMAGE SIZE\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,45 +531,45 @@ type ports struct {
|
||||||
func TestDisplayablePorts(t *testing.T) {
|
func TestDisplayablePorts(t *testing.T) {
|
||||||
cases := []ports{
|
cases := []ports{
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/tcp",
|
expected: "9988/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/udp",
|
expected: "9988/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "0.0.0.0",
|
IP: "0.0.0.0",
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"0.0.0.0:0->9988/tcp",
|
expected: "0.0.0.0:0->9988/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
PublicPort: 8899,
|
PublicPort: 8899,
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/tcp",
|
expected: "9988/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "4.3.2.1",
|
IP: "4.3.2.1",
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
|
@ -490,10 +577,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"4.3.2.1:8899->9988/tcp",
|
expected: "4.3.2.1:8899->9988/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "4.3.2.1",
|
IP: "4.3.2.1",
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
|
@ -501,10 +588,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"4.3.2.1:9988->9988/tcp",
|
expected: "4.3.2.1:9988->9988/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
|
@ -513,10 +600,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/udp, 9988/udp",
|
expected: "9988/udp, 9988/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "1.2.3.4",
|
IP: "1.2.3.4",
|
||||||
PublicPort: 9998,
|
PublicPort: 9998,
|
||||||
|
@ -529,10 +616,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"1.2.3.4:9998-9999->9998-9999/udp",
|
expected: "1.2.3.4:9998-9999->9998-9999/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "1.2.3.4",
|
IP: "1.2.3.4",
|
||||||
PublicPort: 8887,
|
PublicPort: 8887,
|
||||||
|
@ -545,10 +632,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp",
|
expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9998,
|
PrivatePort: 9998,
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
|
@ -557,10 +644,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9998-9999/udp",
|
expected: "9998-9999/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "1.2.3.4",
|
IP: "1.2.3.4",
|
||||||
PrivatePort: 6677,
|
PrivatePort: 6677,
|
||||||
|
@ -572,10 +659,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "udp",
|
Type: "udp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/udp, 1.2.3.4:7766->6677/tcp",
|
expected: "9988/udp, 1.2.3.4:7766->6677/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
IP: "1.2.3.4",
|
IP: "1.2.3.4",
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
|
@ -593,10 +680,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
|
expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 9988,
|
PrivatePort: 9988,
|
||||||
PublicPort: 8899,
|
PublicPort: 8899,
|
||||||
|
@ -613,10 +700,10 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp",
|
expected: "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]types.Port{
|
ports: []types.Port{
|
||||||
{
|
{
|
||||||
PrivatePort: 80,
|
PrivatePort: 80,
|
||||||
Type: "tcp",
|
Type: "tcp",
|
||||||
|
@ -674,7 +761,7 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
Type: "sctp",
|
Type: "sctp",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"80/tcp, 80/udp, 1024/tcp, 1024/udp, 12345/sctp, 1.1.1.1:1024->80/tcp, 1.1.1.1:1024->80/udp, 2.1.1.1:1024->80/tcp, 2.1.1.1:1024->80/udp, 1.1.1.1:80->1024/tcp, 1.1.1.1:80->1024/udp, 2.1.1.1:80->1024/tcp, 2.1.1.1:80->1024/udp",
|
expected: "80/tcp, 80/udp, 1024/tcp, 1024/udp, 12345/sctp, 1.1.1.1:1024->80/tcp, 1.1.1.1:1024->80/udp, 2.1.1.1:1024->80/tcp, 2.1.1.1:1024->80/udp, 1.1.1.1:80->1024/tcp, 1.1.1.1:80->1024/udp, 2.1.1.1:80->1024/tcp, 2.1.1.1:80->1024/udp",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -336,8 +336,8 @@ func (c *diskUsageContainersContext) isActive(container types.Container) bool {
|
||||||
|
|
||||||
func (c *diskUsageContainersContext) Active() string {
|
func (c *diskUsageContainersContext) Active() string {
|
||||||
used := 0
|
used := 0
|
||||||
for _, container := range c.containers {
|
for _, ctr := range c.containers {
|
||||||
if c.isActive(*container) {
|
if c.isActive(*ctr) {
|
||||||
used++
|
used++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,22 +348,21 @@ func (c *diskUsageContainersContext) Active() string {
|
||||||
func (c *diskUsageContainersContext) Size() string {
|
func (c *diskUsageContainersContext) Size() string {
|
||||||
var size int64
|
var size int64
|
||||||
|
|
||||||
for _, container := range c.containers {
|
for _, ctr := range c.containers {
|
||||||
size += container.SizeRw
|
size += ctr.SizeRw
|
||||||
}
|
}
|
||||||
|
|
||||||
return units.HumanSize(float64(size))
|
return units.HumanSize(float64(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *diskUsageContainersContext) Reclaimable() string {
|
func (c *diskUsageContainersContext) Reclaimable() string {
|
||||||
var reclaimable int64
|
var reclaimable, totalSize int64
|
||||||
var totalSize int64
|
|
||||||
|
|
||||||
for _, container := range c.containers {
|
for _, ctr := range c.containers {
|
||||||
if !c.isActive(*container) {
|
if !c.isActive(*ctr) {
|
||||||
reclaimable += container.SizeRw
|
reclaimable += ctr.SizeRw
|
||||||
}
|
}
|
||||||
totalSize += container.SizeRw
|
totalSize += ctr.SizeRw
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalSize > 0 {
|
if totalSize > 0 {
|
||||||
|
|
|
@ -24,9 +24,9 @@ type fakeClient struct {
|
||||||
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
|
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
|
||||||
imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error)
|
imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error)
|
||||||
imageListFunc func(options image.ListOptions) ([]image.Summary, error)
|
imageListFunc func(options image.ListOptions) ([]image.Summary, error)
|
||||||
imageInspectFunc func(image string) (types.ImageInspect, []byte, error)
|
imageInspectFunc func(img string) (types.ImageInspect, []byte, error)
|
||||||
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
|
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
|
||||||
imageHistoryFunc func(image string) ([]image.HistoryResponseItem, error)
|
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
|
||||||
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (cli *fakeClient) Info(_ context.Context) (system.Info, error) {
|
||||||
|
|
||||||
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) {
|
func (cli *fakeClient) ImagePull(_ context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) {
|
||||||
if cli.imagePullFunc != nil {
|
if cli.imagePullFunc != nil {
|
||||||
cli.imagePullFunc(ref, options)
|
return cli.imagePullFunc(ref, options)
|
||||||
}
|
}
|
||||||
return io.NopCloser(strings.NewReader("")), nil
|
return io.NopCloser(strings.NewReader("")), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,15 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
imageCount int
|
imageCount int
|
||||||
imageInspectFunc func(image string) (types.ImageInspect, []byte, error)
|
imageInspectFunc func(img string) (types.ImageInspect, []byte, error)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple",
|
name: "simple",
|
||||||
args: []string{"image"},
|
args: []string{"image"},
|
||||||
imageCount: 1,
|
imageCount: 1,
|
||||||
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
|
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
|
||||||
imageInspectInvocationCount++
|
imageInspectInvocationCount++
|
||||||
assert.Check(t, is.Equal("image", image))
|
assert.Check(t, is.Equal("image", img))
|
||||||
return types.ImageInspect{}, nil, nil
|
return types.ImageInspect{}, nil, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -54,21 +54,21 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
||||||
name: "format",
|
name: "format",
|
||||||
imageCount: 1,
|
imageCount: 1,
|
||||||
args: []string{"--format='{{.ID}}'", "image"},
|
args: []string{"--format='{{.ID}}'", "image"},
|
||||||
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
|
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
|
||||||
imageInspectInvocationCount++
|
imageInspectInvocationCount++
|
||||||
return types.ImageInspect{ID: image}, nil, nil
|
return types.ImageInspect{ID: img}, nil, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "simple-many",
|
name: "simple-many",
|
||||||
args: []string{"image1", "image2"},
|
args: []string{"image1", "image2"},
|
||||||
imageCount: 2,
|
imageCount: 2,
|
||||||
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
|
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
|
||||||
imageInspectInvocationCount++
|
imageInspectInvocationCount++
|
||||||
if imageInspectInvocationCount == 1 {
|
if imageInspectInvocationCount == 1 {
|
||||||
assert.Check(t, is.Equal("image1", image))
|
assert.Check(t, is.Equal("image1", img))
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal("image2", image))
|
assert.Check(t, is.Equal("image2", img))
|
||||||
}
|
}
|
||||||
return types.ImageInspect{}, nil, nil
|
return types.ImageInspect{}, nil, nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -50,18 +50,18 @@ func runDisconnect(ctx context.Context, dockerCli command.Cli, opts disconnectOp
|
||||||
}
|
}
|
||||||
|
|
||||||
func isConnected(network string) func(types.Container) bool {
|
func isConnected(network string) func(types.Container) bool {
|
||||||
return func(container types.Container) bool {
|
return func(ctr types.Container) bool {
|
||||||
if container.NetworkSettings == nil {
|
if ctr.NetworkSettings == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
_, ok := container.NetworkSettings.Networks[network]
|
_, ok := ctr.NetworkSettings.Networks[network]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func not(fn func(types.Container) bool) func(types.Container) bool {
|
func not(fn func(types.Container) bool) func(types.Container) bool {
|
||||||
return func(container types.Container) bool {
|
return func(ctr types.Container) bool {
|
||||||
ok := fn(container)
|
ok := fn(ctr)
|
||||||
return !ok
|
return !ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ func TestNotaryRoleToSigner(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.Check(t, is.Equal(role.String(), notaryRoleToSigner(role)))
|
assert.Check(t, is.Equal(role.String(), notaryRoleToSigner(role)))
|
||||||
}
|
}
|
||||||
assert.Check(t, is.Equal("notarole", notaryRoleToSigner(data.RoleName("notarole"))))
|
assert.Check(t, is.Equal("notarole", notaryRoleToSigner("notarole")))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a role name is "released": either targets/releases or targets TUF roles
|
// check if a role name is "released": either targets/releases or targets TUF roles
|
||||||
|
@ -196,9 +196,9 @@ func TestIsReleasedTarget(t *testing.T) {
|
||||||
for _, role := range data.BaseRoles {
|
for _, role := range data.BaseRoles {
|
||||||
assert.Check(t, is.Equal(role == data.CanonicalTargetsRole, isReleasedTarget(role)))
|
assert.Check(t, is.Equal(role == data.CanonicalTargetsRole, isReleasedTarget(role)))
|
||||||
}
|
}
|
||||||
assert.Check(t, !isReleasedTarget(data.RoleName("targets/not-releases")))
|
assert.Check(t, !isReleasedTarget("targets/not-releases"))
|
||||||
assert.Check(t, !isReleasedTarget(data.RoleName("random")))
|
assert.Check(t, !isReleasedTarget("random"))
|
||||||
assert.Check(t, !isReleasedTarget(data.RoleName("targets/releases/subrole")))
|
assert.Check(t, !isReleasedTarget("targets/releases/subrole"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a mock delegation with a given name and no keys
|
// creates a mock delegation with a given name and no keys
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
|
|
||||||
// Container creates a container with default values.
|
// Container creates a container with default values.
|
||||||
// Any number of container function builder can be passed to augment it.
|
// Any number of container function builder can be passed to augment it.
|
||||||
func Container(name string, builders ...func(container *types.Container)) *types.Container {
|
func Container(name string, builders ...func(c *types.Container)) *types.Container {
|
||||||
// now := time.Now()
|
// now := time.Now()
|
||||||
// onehourago := now.Add(-120 * time.Minute)
|
// onehourago := now.Add(-120 * time.Minute)
|
||||||
container := &types.Container{
|
ctr := &types.Container{
|
||||||
ID: "container_id",
|
ID: "container_id",
|
||||||
Names: []string{"/" + name},
|
Names: []string{"/" + name},
|
||||||
Command: "top",
|
Command: "top",
|
||||||
|
@ -21,10 +21,10 @@ func Container(name string, builders ...func(container *types.Container)) *types
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, builder := range builders {
|
for _, builder := range builders {
|
||||||
builder(container)
|
builder(ctr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return container
|
return ctr
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLabel adds a label to the container
|
// WithLabel adds a label to the container
|
||||||
|
@ -45,14 +45,14 @@ func WithName(name string) func(*types.Container) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithPort adds a port mapping to the container
|
// WithPort adds a port mapping to the container
|
||||||
func WithPort(privateport, publicport uint16, builders ...func(*types.Port)) func(*types.Container) {
|
func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) func(*types.Container) {
|
||||||
return func(c *types.Container) {
|
return func(c *types.Container) {
|
||||||
if c.Ports == nil {
|
if c.Ports == nil {
|
||||||
c.Ports = []types.Port{}
|
c.Ports = []types.Port{}
|
||||||
}
|
}
|
||||||
port := &types.Port{
|
port := &types.Port{
|
||||||
PrivatePort: privateport,
|
PrivatePort: privatePort,
|
||||||
PublicPort: publicport,
|
PublicPort: publicPort,
|
||||||
}
|
}
|
||||||
for _, builder := range builders {
|
for _, builder := range builders {
|
||||||
builder(port)
|
builder(port)
|
||||||
|
|
Loading…
Reference in New Issue