mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix service update of Args
add a unit test Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
3d231c78e8
commit
07b59ef210
3 changed files with 44 additions and 3 deletions
|
@ -45,7 +45,7 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID stri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = updateService(&service.Spec, flags)
|
err = updateService(flags, &service.Spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateService(spec *swarm.ServiceSpec, flags *pflag.FlagSet) error {
|
func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
||||||
|
|
||||||
updateString := func(flag string, field *string) {
|
updateString := func(flag string, field *string) {
|
||||||
if flags.Changed(flag) {
|
if flags.Changed(flag) {
|
||||||
|
@ -123,7 +123,7 @@ func updateService(spec *swarm.ServiceSpec, flags *pflag.FlagSet) error {
|
||||||
updateLabels(flags, &spec.Labels)
|
updateLabels(flags, &spec.Labels)
|
||||||
updateString("image", &cspec.Image)
|
updateString("image", &cspec.Image)
|
||||||
updateSlice("command", &cspec.Command)
|
updateSlice("command", &cspec.Command)
|
||||||
updateSlice("arg", &cspec.Command)
|
updateSlice("arg", &cspec.Args)
|
||||||
updateListOpts("env", &cspec.Env)
|
updateListOpts("env", &cspec.Env)
|
||||||
updateString("workdir", &cspec.Dir)
|
updateString("workdir", &cspec.Dir)
|
||||||
updateString(flagUser, &cspec.User)
|
updateString(flagUser, &cspec.User)
|
||||||
|
|
26
api/client/service/update_test.go
Normal file
26
api/client/service/update_test.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/testutil/assert"
|
||||||
|
"github.com/docker/engine-api/types/swarm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUpdateServiceCommandAndArgs(t *testing.T) {
|
||||||
|
flags := newUpdateCommand(nil).Flags()
|
||||||
|
flags.Set("command", "the")
|
||||||
|
flags.Set("command", "new")
|
||||||
|
flags.Set("command", "command")
|
||||||
|
flags.Set("arg", "the")
|
||||||
|
flags.Set("arg", "new args")
|
||||||
|
|
||||||
|
spec := &swarm.ServiceSpec{}
|
||||||
|
cspec := &spec.TaskTemplate.ContainerSpec
|
||||||
|
cspec.Command = []string{"old", "command"}
|
||||||
|
cspec.Args = []string{"old", "args"}
|
||||||
|
|
||||||
|
updateService(flags, spec)
|
||||||
|
assert.EqualStringSlice(t, cspec.Command, []string{"the", "new", "command"})
|
||||||
|
assert.EqualStringSlice(t, cspec.Args, []string{"the", "new args"})
|
||||||
|
}
|
|
@ -19,6 +19,21 @@ func Equal(t TestingT, actual, expected interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//EqualStringSlice compares two slices and fails the test if they do not contain
|
||||||
|
// the same items.
|
||||||
|
func EqualStringSlice(t TestingT, actual, expected []string) {
|
||||||
|
if len(actual) != len(expected) {
|
||||||
|
t.Fatalf("Expected (length %d): %q\nActual (length %d): %q",
|
||||||
|
len(expected), expected, len(actual), actual)
|
||||||
|
}
|
||||||
|
for i, item := range actual {
|
||||||
|
if item != expected[i] {
|
||||||
|
t.Fatalf("Slices differ at element %d, expected %q got %q",
|
||||||
|
i, expected[i], item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NilError asserts that the error is nil, otherwise it fails the test.
|
// NilError asserts that the error is nil, otherwise it fails the test.
|
||||||
func NilError(t TestingT, err error) {
|
func NilError(t TestingT, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue