github.com/LazyboyChen7/engine@v17.12.1-ce-rc2+incompatible/integration-cli/docker_cli_service_scale_test.go (about)

     1  // +build !windows
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  
     9  	"github.com/docker/docker/integration-cli/checker"
    10  	"github.com/go-check/check"
    11  )
    12  
    13  func (s *DockerSwarmSuite) TestServiceScale(c *check.C) {
    14  	d := s.AddDaemon(c, true, true)
    15  
    16  	service1Name := "TestService1"
    17  	service1Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service1Name, defaultSleepImage}, sleepCommandForDaemonPlatform()...)
    18  
    19  	// global mode
    20  	service2Name := "TestService2"
    21  	service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", defaultSleepImage}, sleepCommandForDaemonPlatform()...)
    22  
    23  	// Create services
    24  	out, err := d.Cmd(service1Args...)
    25  	c.Assert(err, checker.IsNil)
    26  
    27  	out, err = d.Cmd(service2Args...)
    28  	c.Assert(err, checker.IsNil)
    29  
    30  	out, err = d.Cmd("service", "scale", "TestService1=2")
    31  	c.Assert(err, checker.IsNil)
    32  
    33  	out, err = d.Cmd("service", "scale", "TestService1=foobar")
    34  	c.Assert(err, checker.NotNil)
    35  
    36  	str := fmt.Sprintf("%s: invalid replicas value %s", service1Name, "foobar")
    37  	if !strings.Contains(out, str) {
    38  		c.Errorf("got: %s, expected has sub string: %s", out, str)
    39  	}
    40  
    41  	out, err = d.Cmd("service", "scale", "TestService1=-1")
    42  	c.Assert(err, checker.NotNil)
    43  
    44  	str = fmt.Sprintf("%s: invalid replicas value %s", service1Name, "-1")
    45  	if !strings.Contains(out, str) {
    46  		c.Errorf("got: %s, expected has sub string: %s", out, str)
    47  	}
    48  
    49  	// TestService2 is a global mode
    50  	out, err = d.Cmd("service", "scale", "TestService2=2")
    51  	c.Assert(err, checker.NotNil)
    52  
    53  	str = fmt.Sprintf("%s: scale can only be used with replicated mode\n", service2Name)
    54  	if out != str {
    55  		c.Errorf("got: %s, expected: %s", out, str)
    56  	}
    57  }