docker_cli_version_test.go 1.5 KB

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