docker_cli_version_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "strings"
  4. "github.com/docker/docker/pkg/integration/checker"
  5. "github.com/go-check/check"
  6. )
  7. // ensure docker version works
  8. func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) {
  9. out, _ := dockerCmd(c, "version")
  10. stringsToCheck := map[string]int{
  11. "Client:": 1,
  12. "Server:": 1,
  13. " Version:": 2,
  14. " API version:": 2,
  15. " Go version:": 2,
  16. " Git commit:": 2,
  17. " OS/Arch:": 2,
  18. " Built:": 2,
  19. }
  20. for k, v := range stringsToCheck {
  21. c.Assert(strings.Count(out, k), checker.Equals, v, check.Commentf("The count of %v in %s does not match excepted", k, out))
  22. }
  23. }
  24. // ensure the Windows daemon return the correct platform string
  25. func (s *DockerSuite) TestVersionPlatform_w(c *check.C) {
  26. testRequires(c, DaemonIsWindows)
  27. testVersionPlatform(c, "windows/amd64")
  28. }
  29. // ensure the Linux daemon return the correct platform string
  30. func (s *DockerSuite) TestVersionPlatform_l(c *check.C) {
  31. testRequires(c, DaemonIsLinux)
  32. testVersionPlatform(c, "linux")
  33. }
  34. func testVersionPlatform(c *check.C, platform string) {
  35. out, _ := dockerCmd(c, "version")
  36. expected := "OS/Arch: " + platform
  37. split := strings.Split(out, "\n")
  38. c.Assert(len(split) >= 14, checker.Equals, true, check.Commentf("got %d lines from version", len(split)))
  39. // Verify the second 'OS/Arch' matches the platform. Experimental has
  40. // more lines of output than 'regular'
  41. bFound := false
  42. for i := 14; i < len(split); i++ {
  43. if strings.Contains(split[i], expected) {
  44. bFound = true
  45. break
  46. }
  47. }
  48. c.Assert(bFound, checker.Equals, true, check.Commentf("Could not find server '%s' in '%s'", expected, out))
  49. }