docker_api_info_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "net/http"
  4. "fmt"
  5. "github.com/docker/docker/client"
  6. "github.com/docker/docker/integration-cli/checker"
  7. "github.com/docker/docker/integration-cli/request"
  8. "github.com/go-check/check"
  9. "golang.org/x/net/context"
  10. )
  11. func (s *DockerSuite) TestInfoAPI(c *check.C) {
  12. cli, err := client.NewEnvClient()
  13. c.Assert(err, checker.IsNil)
  14. defer cli.Close()
  15. info, err := cli.Info(context.Background())
  16. c.Assert(err, checker.IsNil)
  17. // always shown fields
  18. stringsToCheck := []string{
  19. "ID",
  20. "Containers",
  21. "ContainersRunning",
  22. "ContainersPaused",
  23. "ContainersStopped",
  24. "Images",
  25. "LoggingDriver",
  26. "OperatingSystem",
  27. "NCPU",
  28. "OSType",
  29. "Architecture",
  30. "MemTotal",
  31. "KernelVersion",
  32. "Driver",
  33. "ServerVersion",
  34. "SecurityOptions"}
  35. out := fmt.Sprintf("%+v", info)
  36. for _, linePrefix := range stringsToCheck {
  37. c.Assert(out, checker.Contains, linePrefix)
  38. }
  39. }
  40. func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) {
  41. testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
  42. res, body, err := request.Get("/v1.20/info")
  43. c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
  44. c.Assert(err, checker.IsNil)
  45. b, err := request.ReadBody(body)
  46. c.Assert(err, checker.IsNil)
  47. out := string(b)
  48. c.Assert(out, checker.Contains, "ExecutionDriver")
  49. c.Assert(out, checker.Contains, "not supported")
  50. }