github.com/khulnasoft-lab/khulnasoft@v26.0.1-0.20240328202558-330a6f959fe0+incompatible/integration-cli/docker_cli_service_scale_test.go (about)

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