github.com/MOXA-ISD/edge-library-libcompose@v0.4.1-0.20200417083957-c90441e63650/integration/scale_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "strings" 6 7 . "gopkg.in/check.v1" 8 ) 9 10 func (s *CliSuite) TestScale(c *C) { 11 p := s.ProjectFromText(c, "up", SimpleTemplate) 12 13 name := fmt.Sprintf("%s_%s_1", p, "hello") 14 name2 := fmt.Sprintf("%s_%s_2", p, "hello") 15 cn := s.GetContainerByName(c, name) 16 c.Assert(cn, NotNil) 17 18 c.Assert(cn.State.Running, Equals, true) 19 20 containers := s.GetContainersByProject(c, p) 21 c.Assert(1, Equals, len(containers)) 22 23 s.FromText(c, p, "scale", "hello=2", SimpleTemplate) 24 25 containers = s.GetContainersByProject(c, p) 26 c.Assert(2, Equals, len(containers)) 27 28 for _, name := range []string{name, name2} { 29 cn := s.GetContainerByName(c, name) 30 c.Assert(cn, NotNil) 31 c.Assert(cn.State.Running, Equals, true) 32 } 33 34 s.FromText(c, p, "scale", "--timeout", "0", "hello=1", SimpleTemplate) 35 containers = s.GetContainersByProject(c, p) 36 c.Assert(1, Equals, len(containers)) 37 38 cn = s.GetContainerByName(c, name) 39 c.Assert(cn, IsNil) 40 41 cn = s.GetContainerByName(c, name2) 42 c.Assert(cn, NotNil) 43 c.Assert(cn.State.Running, Equals, true) 44 } 45 46 func (s *CliSuite) TestScaleWithHostPortWarning(c *C) { 47 template := ` 48 test: 49 image: busybox 50 ports: 51 - 8001:8001 52 ` 53 p := s.ProjectFromText(c, "up", template) 54 55 name := fmt.Sprintf("%s_%s_1", p, "test") 56 cn := s.GetContainerByName(c, name) 57 c.Assert(cn, NotNil) 58 59 c.Assert(cn.State.Running, Equals, true) 60 61 containers := s.GetContainersByProject(c, p) 62 c.Assert(1, Equals, len(containers)) 63 64 _, output := s.FromTextCaptureOutput(c, p, "scale", "test=2", template) 65 66 // Assert warning is given when trying to scale a service that specifies a host port 67 c.Assert(strings.Contains(output, "If multiple containers for this service are created on a single host, the port will clash."), Equals, true, Commentf(output)) 68 }