github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration-cli/docker_cli_service_scale_test.go (about)

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