Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
  • Loading branch information
simonferquel committed Nov 2, 2017
1 parent ee86d46 commit a85b1a4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
Binary file added cli/command/service/debug.test
Binary file not shown.
2 changes: 1 addition & 1 deletion cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ type isolationOpts struct {

func (o *isolationOpts) Set(value string) error {
o.source = value
tv := container.Isolation(value)
tv := container.Isolation(strings.ToLower(value))
if tv.IsDefault() || tv.IsHyperV() || tv.IsProcess() {
o.value = &tv
return nil
Expand Down
55 changes: 55 additions & 0 deletions cli/command/service/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -85,3 +87,56 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
_, err := opt.toHealthConfig()
assert.EqualError(t, err, "--no-healthcheck conflicts with --health-* options")
}

func TestIsolationParsing(t *testing.T) {
cases := []struct {
name string
source string
expectedError string
expectedIsolation container.Isolation
}{
{
name: "empty",
source: "",
expectedIsolation: container.IsolationEmpty,
},
{
name: "default",
source: "default",
expectedIsolation: container.IsolationDefault,
},
{
name: "process",
source: "process",
expectedIsolation: container.IsolationProcess,
},
{
name: "hyperv",
source: "hyperv",
expectedIsolation: container.IsolationHyperV,
},
{
name: "caseInsensitive",
source: "HyperV",
expectedIsolation: container.IsolationHyperV,
},
{
name: "unknown",
source: "test",
expectedError: "Unknown isolation mode test. Valid values are default, process, hyperv",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
opts := isolationOpts{}
err := opts.Set(c.source)
if c.expectedError == "" {
require.NoError(t, err)
require.Equal(t, c.expectedIsolation, opts.Value())
} else {
require.EqualError(t, err, c.expectedError)
}
})
}

}
20 changes: 20 additions & 0 deletions cli/command/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,23 @@ func TestUpdateStopSignal(t *testing.T) {
updateService(nil, nil, flags, spec)
assert.Equal(t, "SIGWINCH", cspec.StopSignal)
}

func TestUpdateIsolationValid(t *testing.T) {
flags := newUpdateCommand(nil).Flags()
err := flags.Set("isolation", "process")
require.NoError(t, err)
spec := swarm.ServiceSpec{
TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{},
},
}
err = updateService(context.Background(), nil, flags, &spec)
require.NoError(t, err)
assert.Equal(t, container.IsolationProcess, spec.TaskTemplate.ContainerSpec.Isolation)
}

func TestUpdateIsolationInvalid(t *testing.T) {
flags := newUpdateCommand(nil).Flags()
err := flags.Set("isolation", "test")
require.EqualError(t, err, "invalid argument \"test\" for \"--isolation\" flag: Unknown isolation mode test. Valid values are default, process, hyperv")
}

0 comments on commit a85b1a4

Please sign in to comment.