1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/docker_cli_stack_test.go
Yong Tang 1e9d04c458 Allow docker deploy command accept filename with/without extension
This fix tries to address the issue raised in 25855 where the command
`docker deploy` can only accept a STACK without extension of `.dab`.
In other words, `docker deploy hellojavaee.dab` gives an error:
```
Bundle hellojavaee.dab.dab not found. Specify the path with --file
```

This fix updates the way namespace STACK is taken so that in case
`STACK.dab` is provided with `docker deploy`:
```
$ docker deploy STACK.dab
```
The `STACK` is used as namespace (instead of `STACK.dab`).

NOTE: This fix will only allows `.dab` extension in namespace, because
it is not possible to have a namespace with `.` in the middle. In other
words, a namespace `hello.java.ee` will not work anyway (whether the file
`hello.java.ee` exists or not).

An additional integration test has been added to cover the changes.

This fix fixes 25855.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2016-10-14 11:44:15 -07:00

109 lines
3.4 KiB
Go

// +build experimental
package main
import (
"io/ioutil"
"os"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
)
func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
d := s.AddDaemon(c, true, true)
stackArgs := append([]string{"stack", "remove", "UNKNOWN_STACK"})
out, err := d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
}
func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
d := s.AddDaemon(c, true, true)
stackArgs := append([]string{"stack", "ps", "UNKNOWN_STACK"})
out, err := d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
}
func (s *DockerSwarmSuite) TestStackServices(c *check.C) {
d := s.AddDaemon(c, true, true)
stackArgs := append([]string{"stack", "services", "UNKNOWN_STACK"})
out, err := d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
}
// testDAB is the DAB JSON used for testing.
// TODO: Use template/text and substitute "Image" with the result of
// `docker inspect --format '{{index .RepoDigests 0}}' busybox:latest`
const testDAB = `{
"Version": "0.1",
"Services": {
"srv1": {
"Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0",
"Command": ["top"]
},
"srv2": {
"Image": "busybox@sha256:e4f93f6ed15a0cdd342f5aae387886fba0ab98af0a102da6276eaf24d6e6ade0",
"Command": ["tail"],
"Args": ["-f", "/dev/null"]
}
}
}`
func (s *DockerSwarmSuite) TestStackWithDAB(c *check.C) {
// setup
testStackName := "test"
testDABFileName := testStackName + ".dab"
defer os.RemoveAll(testDABFileName)
err := ioutil.WriteFile(testDABFileName, []byte(testDAB), 0444)
c.Assert(err, checker.IsNil)
d := s.AddDaemon(c, true, true)
// deploy
stackArgs := []string{"stack", "deploy", testStackName}
out, err := d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "Loading bundle from test.dab\n")
c.Assert(out, checker.Contains, "Creating service test_srv1\n")
c.Assert(out, checker.Contains, "Creating service test_srv2\n")
// ls
stackArgs = []string{"stack", "ls"}
out, err = d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "NAME SERVICES\n"+"test 2\n")
// rm
stackArgs = []string{"stack", "rm", testStackName}
out, err = d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "Removing service test_srv1\n")
c.Assert(out, checker.Contains, "Removing service test_srv2\n")
// ls (empty)
stackArgs = []string{"stack", "ls"}
out, err = d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, check.Equals, "NAME SERVICES\n")
}
func (s *DockerSwarmSuite) TestStackWithDABExtension(c *check.C) {
// setup
testStackName := "test.dab"
testDABFileName := testStackName
defer os.RemoveAll(testDABFileName)
err := ioutil.WriteFile(testDABFileName, []byte(testDAB), 0444)
c.Assert(err, checker.IsNil)
d := s.AddDaemon(c, true, true)
// deploy
stackArgs := []string{"stack", "deploy", testStackName}
out, err := d.Cmd(stackArgs...)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "Loading bundle from test.dab\n")
c.Assert(out, checker.Contains, "Creating service test_srv1\n")
c.Assert(out, checker.Contains, "Creating service test_srv2\n")
}