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_config_create_test.go
Kir Kolyshkin ac038eab29 integration-cli: error report improvements
1. After running d.Cmd(), in case an error is returned, it makes sense
to print command output, as its stderr may contain a clue about what
went wrong. This is by no means complete, just as far as I could go.

2. In case the comment in c.Assert is a constant string, it's better
to provide it as a comment which will be printed.

3. An arbitrary string should not be passed on to a function expecting
%-style formatting. Use %s to fix this.

4. Print the output string before transformation, not after.

5. Unify the output format (drop "out:" prefix").

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-08-14 12:52:30 +03:00

33 lines
878 B
Go

// +build !windows
package main
import (
"io/ioutil"
"os"
"strings"
"github.com/docker/docker/integration-cli/checker"
"github.com/go-check/check"
)
func (s *DockerSwarmSuite) TestConfigCreateWithFile(c *check.C) {
d := s.AddDaemon(c, true, true)
testFile, err := ioutil.TempFile("", "configCreateTest")
c.Assert(err, checker.IsNil) // ensure temp file is created
defer os.Remove(testFile.Name())
testData := "TESTINGDATA"
_, err = testFile.Write([]byte(testData))
c.Assert(err, checker.IsNil) // ensure temp file is written
testName := "test_config"
out, err := d.Cmd("config", "create", testName, testFile.Name())
c.Assert(err, checker.IsNil, check.Commentf("%s", out))
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
id := strings.TrimSpace(out)
config := d.GetConfig(c, id)
c.Assert(config.Spec.Name, checker.Equals, testName)
}