2016-09-19 08:40:44 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2019-04-04 13:23:19 +00:00
|
|
|
"gotest.tools/assert"
|
2016-09-19 08:40:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceScale(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
service1Name := "TestService1"
|
2019-07-08 16:42:08 +00:00
|
|
|
service1Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service1Name, "busybox"}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 08:40:44 +00:00
|
|
|
|
|
|
|
// global mode
|
|
|
|
service2Name := "TestService2"
|
2019-07-08 16:42:08 +00:00
|
|
|
service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", "busybox"}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 08:40:44 +00:00
|
|
|
|
|
|
|
// Create services
|
2018-07-09 17:40:34 +00:00
|
|
|
_, err := d.Cmd(service1Args...)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 08:40:44 +00:00
|
|
|
|
2018-07-09 17:40:34 +00:00
|
|
|
_, err = d.Cmd(service2Args...)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 08:40:44 +00:00
|
|
|
|
2018-07-09 17:40:34 +00:00
|
|
|
_, err = d.Cmd("service", "scale", "TestService1=2")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 08:40:44 +00:00
|
|
|
|
2018-07-09 17:40:34 +00:00
|
|
|
out, err := d.Cmd("service", "scale", "TestService1=foobar")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 08:40:44 +00:00
|
|
|
|
|
|
|
str := fmt.Sprintf("%s: invalid replicas value %s", service1Name, "foobar")
|
|
|
|
if !strings.Contains(out, str) {
|
|
|
|
c.Errorf("got: %s, expected has sub string: %s", out, str)
|
|
|
|
}
|
|
|
|
|
2017-09-28 00:47:51 +00:00
|
|
|
out, err = d.Cmd("service", "scale", "TestService1=-1")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 08:40:44 +00:00
|
|
|
|
|
|
|
str = fmt.Sprintf("%s: invalid replicas value %s", service1Name, "-1")
|
|
|
|
if !strings.Contains(out, str) {
|
|
|
|
c.Errorf("got: %s, expected has sub string: %s", out, str)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestService2 is a global mode
|
2017-09-28 00:47:51 +00:00
|
|
|
out, err = d.Cmd("service", "scale", "TestService2=2")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 08:40:44 +00:00
|
|
|
|
|
|
|
str = fmt.Sprintf("%s: scale can only be used with replicated mode\n", service2Name)
|
|
|
|
if out != str {
|
|
|
|
c.Errorf("got: %s, expected: %s", out, str)
|
|
|
|
}
|
|
|
|
}
|