mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17256 from liaoqingwei/16756-docker_cli_config_test
Use of checkers on docker_cli_config_test.go
This commit is contained in:
commit
962243e387
1 changed files with 28 additions and 42 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/autogen/dockerversion"
|
||||
"github.com/docker/docker/pkg/homedir"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -31,7 +32,7 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
|
|||
homeKey := homedir.Key()
|
||||
homeVal := homedir.Get()
|
||||
tmpDir, err := ioutil.TempDir("", "fake-home")
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
dotDocker := filepath.Join(tmpDir, ".docker")
|
||||
|
@ -46,46 +47,34 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
|
|||
}`
|
||||
|
||||
err = ioutil.WriteFile(tmpCfg, []byte(data), 0600)
|
||||
if err != nil {
|
||||
c.Fatalf("Err creating file(%s): %v", tmpCfg, err)
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
cmd := exec.Command(dockerBinary, "-H="+server.URL[7:], "ps")
|
||||
out, _, _ := runCommandWithOutput(cmd)
|
||||
|
||||
if headers["User-Agent"] == nil {
|
||||
c.Fatalf("Missing User-Agent: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(headers["User-Agent"], checker.NotNil, check.Commentf("Missing User-Agent"))
|
||||
|
||||
if headers["User-Agent"][0] != "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")" {
|
||||
c.Fatalf("Badly formatted User-Agent: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(headers["User-Agent"][0], checker.Equals, "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")", check.Commentf("Badly formatted User-Agent,out:%v", out))
|
||||
|
||||
c.Assert(headers["Myheader"], checker.NotNil)
|
||||
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("Missing/bad header,out:%v", out))
|
||||
|
||||
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
|
||||
c.Fatalf("Missing/bad header: %q\nout:%v", headers, out)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestConfigDir(c *check.C) {
|
||||
cDir, err := ioutil.TempDir("", "fake-home")
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer os.RemoveAll(cDir)
|
||||
|
||||
// First make sure pointing to empty dir doesn't generate an error
|
||||
out, rc := dockerCmd(c, "--config", cDir, "ps")
|
||||
|
||||
if rc != 0 {
|
||||
c.Fatalf("ps1 didn't work:\nrc:%d\nout%s", rc, out)
|
||||
}
|
||||
dockerCmd(c, "--config", cDir, "ps")
|
||||
|
||||
// Test with env var too
|
||||
cmd := exec.Command(dockerBinary, "ps")
|
||||
cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
|
||||
out, rc, err = runCommandWithOutput(cmd)
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
|
||||
if rc != 0 || err != nil {
|
||||
c.Fatalf("ps2 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)
|
||||
}
|
||||
c.Assert(err, checker.IsNil, check.Commentf("ps2 didn't work,out:%v", out))
|
||||
|
||||
// Start a server so we can check to see if the config file was
|
||||
// loaded properly
|
||||
|
@ -104,36 +93,34 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
|
|||
|
||||
tmpCfg := filepath.Join(cDir, "config.json")
|
||||
err = ioutil.WriteFile(tmpCfg, []byte(data), 0600)
|
||||
if err != nil {
|
||||
c.Fatalf("Err creating file(%s): %v", tmpCfg, err)
|
||||
}
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Err creating file"))
|
||||
|
||||
cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps")
|
||||
out, _, _ = runCommandWithOutput(cmd)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
|
||||
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
|
||||
c.Fatalf("ps3 - Missing header: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out))
|
||||
c.Assert(headers["Myheader"], checker.NotNil)
|
||||
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps3 - Missing header,out:%v", out))
|
||||
|
||||
// Reset headers and try again using env var this time
|
||||
headers = map[string][]string{}
|
||||
cmd = exec.Command(dockerBinary, "-H="+server.URL[7:], "ps")
|
||||
cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
|
||||
out, _, _ = runCommandWithOutput(cmd)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
|
||||
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
|
||||
c.Fatalf("ps4 - Missing header: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil, check.Commentf("%v", out))
|
||||
c.Assert(headers["Myheader"], checker.NotNil)
|
||||
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps4 - Missing header,out:%v", out))
|
||||
|
||||
// Reset headers and make sure flag overrides the env var
|
||||
headers = map[string][]string{}
|
||||
cmd = exec.Command(dockerBinary, "--config", cDir, "-H="+server.URL[7:], "ps")
|
||||
cmd.Env = append(os.Environ(), "DOCKER_CONFIG=MissingDir")
|
||||
out, _, _ = runCommandWithOutput(cmd)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
|
||||
if headers["Myheader"] == nil || headers["Myheader"][0] != "MyValue" {
|
||||
c.Fatalf("ps5 - Missing header: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out))
|
||||
c.Assert(headers["Myheader"], checker.NotNil)
|
||||
c.Assert(headers["Myheader"][0], checker.Equals, "MyValue", check.Commentf("ps5 - Missing header,out:%v", out))
|
||||
|
||||
// Reset headers and make sure flag overrides the env var.
|
||||
// Almost same as previous but make sure the "MissingDir" isn't
|
||||
|
@ -141,10 +128,9 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
|
|||
headers = map[string][]string{}
|
||||
cmd = exec.Command(dockerBinary, "--config", "MissingDir", "-H="+server.URL[7:], "ps")
|
||||
cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
|
||||
out, _, _ = runCommandWithOutput(cmd)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
|
||||
if headers["Myheader"] != nil {
|
||||
c.Fatalf("ps6 - Headers are there but shouldn't be: %q\nout:%v", headers, out)
|
||||
}
|
||||
c.Assert(err, checker.NotNil, check.Commentf("out:%v", out))
|
||||
c.Assert(headers["Myheader"], checker.IsNil, check.Commentf("ps6 - Headers shouldn't be the expected value,out:%v", out))
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue