2016-09-19 04:40:44 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2016-09-19 04:40:44 -04:00
|
|
|
"github.com/go-check/check"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSwarmSuite) TestServiceScale(c *check.C) {
|
|
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
|
|
|
|
service1Name := "TestService1"
|
2017-05-18 15:23:28 -04:00
|
|
|
service1Args := append([]string{"service", "create", "--no-resolve-image", "--name", service1Name, defaultSleepImage}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
|
|
|
// global mode
|
|
|
|
service2Name := "TestService2"
|
2017-05-18 15:23:28 -04:00
|
|
|
service2Args := append([]string{"service", "create", "--no-resolve-image", "--name", service2Name, "--mode=global", defaultSleepImage}, sleepCommandForDaemonPlatform()...)
|
2016-09-19 04:40:44 -04:00
|
|
|
|
|
|
|
// Create services
|
|
|
|
out, err := d.Cmd(service1Args...)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, err = d.Cmd(service2Args...)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "scale", "TestService1=2")
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "scale", "TestService1=foobar")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err = d.Cmd("service", "scale", "TestService1=-1")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
|
|
|
|
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
|
|
|
|
out, err = d.Cmd("service", "scale", "TestService2=2")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|