integration-cli/docker_cli_service_scale_test.go
5ba203e7
 // +build !windows
 
 package main
 
 import (
 	"fmt"
 	"strings"
e25352a4
 	"testing"
5ba203e7
 
6345208b
 	"gotest.tools/assert"
5ba203e7
 )
 
64a928a3
 func (s *DockerSwarmSuite) TestServiceScale(c *testing.T) {
5ba203e7
 	d := s.AddDaemon(c, true, true)
 
 	service1Name := "TestService1"
a63a02fe
 	service1Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service1Name, "busybox"}, sleepCommandForDaemonPlatform()...)
5ba203e7
 
 	// global mode
 	service2Name := "TestService2"
a63a02fe
 	service2Args := append([]string{"service", "create", "--detach", "--no-resolve-image", "--name", service2Name, "--mode=global", "busybox"}, sleepCommandForDaemonPlatform()...)
5ba203e7
 
 	// Create services
ddd8a657
 	_, err := d.Cmd(service1Args...)
6345208b
 	assert.NilError(c, err)
5ba203e7
 
ddd8a657
 	_, err = d.Cmd(service2Args...)
6345208b
 	assert.NilError(c, err)
5ba203e7
 
ddd8a657
 	_, err = d.Cmd("service", "scale", "TestService1=2")
6345208b
 	assert.NilError(c, err)
5ba203e7
 
ddd8a657
 	out, err := d.Cmd("service", "scale", "TestService1=foobar")
6345208b
 	assert.ErrorContains(c, err, "")
5ba203e7
 
 	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)
 	}
 
0ad02941
 	out, err = d.Cmd("service", "scale", "TestService1=-1")
6345208b
 	assert.ErrorContains(c, err, "")
5ba203e7
 
 	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
0ad02941
 	out, err = d.Cmd("service", "scale", "TestService2=2")
6345208b
 	assert.ErrorContains(c, err, "")
5ba203e7
 
 	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)
 	}
 }