2016-09-19 04:40:44 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2019-04-04 09:23:19 -04:00
|
|
|
"gotest.tools/assert"
|
2016-09-19 04:40:44 -04:00
|
|
|
)
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerSwarmSuite) TestServiceScale(c *testing.T) {
|
2016-09-19 04:40:44 -04:00
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
service1Name := "TestService1"
|
2019-07-08 12:42:08 -04:00
|
|
|
service1Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service1Name, "busybox"}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
|
|
|
// global mode
|
|
|
|
service2Name := "TestService2"
|
2019-07-08 12:42:08 -04:00
|
|
|
service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", "busybox"}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
|
|
|
// Create services
|
2018-07-09 13:40:34 -04:00
|
|
|
_, err := d.Cmd(service1Args...)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
_, err = d.Cmd(service2Args...)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
_, err = d.Cmd("service", "scale", "TestService1=2")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
2018-07-09 13:40:34 -04:00
|
|
|
out, err := d.Cmd("service", "scale", "TestService1=foobar")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 04:40:44 -04: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-27 20:47:51 -04:00
|
|
|
out, err = d.Cmd("service", "scale", "TestService1=-1")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 04:40:44 -04: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-27 20:47:51 -04:00
|
|
|
out, err = d.Cmd("service", "scale", "TestService2=2")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2016-09-19 04:40:44 -04: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)
|
|
|
|
}
|
|
|
|
}
|