docker_api_info_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package main
  2. import (
  3. "net/http"
  4. "encoding/json"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/integration-cli/checker"
  7. "github.com/docker/docker/integration-cli/request"
  8. "github.com/docker/docker/pkg/testutil"
  9. "github.com/go-check/check"
  10. )
  11. func (s *DockerSuite) TestInfoAPI(c *check.C) {
  12. endpoint := "/info"
  13. status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
  14. c.Assert(status, checker.Equals, http.StatusOK)
  15. c.Assert(err, checker.IsNil)
  16. // always shown fields
  17. stringsToCheck := []string{
  18. "ID",
  19. "Containers",
  20. "ContainersRunning",
  21. "ContainersPaused",
  22. "ContainersStopped",
  23. "Images",
  24. "LoggingDriver",
  25. "OperatingSystem",
  26. "NCPU",
  27. "OSType",
  28. "Architecture",
  29. "MemTotal",
  30. "KernelVersion",
  31. "Driver",
  32. "ServerVersion",
  33. "SecurityOptions"}
  34. out := string(body)
  35. for _, linePrefix := range stringsToCheck {
  36. c.Assert(out, checker.Contains, linePrefix)
  37. }
  38. }
  39. // TestInfoAPIRuncCommit tests that dockerd is able to obtain RunC version
  40. // information, and that the version matches the expected version
  41. func (s *DockerSuite) TestInfoAPIRuncCommit(c *check.C) {
  42. testRequires(c, DaemonIsLinux) // Windows does not have RunC version information
  43. res, body, err := request.Get("/v1.30/info")
  44. c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
  45. c.Assert(err, checker.IsNil)
  46. b, err := testutil.ReadBody(body)
  47. c.Assert(err, checker.IsNil)
  48. var i types.Info
  49. c.Assert(json.Unmarshal(b, &i), checker.IsNil)
  50. c.Assert(i.RuncCommit.ID, checker.Not(checker.Equals), "N/A")
  51. c.Assert(i.RuncCommit.ID, checker.Equals, i.RuncCommit.Expected)
  52. }
  53. func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) {
  54. testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
  55. endpoint := "/v1.20/info"
  56. status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
  57. c.Assert(status, checker.Equals, http.StatusOK)
  58. c.Assert(err, checker.IsNil)
  59. out := string(body)
  60. c.Assert(out, checker.Contains, "ExecutionDriver")
  61. c.Assert(out, checker.Contains, "not supported")
  62. }