docker_api_inspect_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "strings"
  6. "github.com/go-check/check"
  7. )
  8. func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
  9. out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
  10. cleanedContainerID := strings.TrimSpace(out)
  11. endpoint := "/containers/" + cleanedContainerID + "/json"
  12. status, body, err := sockRequest("GET", endpoint, nil)
  13. c.Assert(status, check.Equals, http.StatusOK)
  14. c.Assert(err, check.IsNil)
  15. var inspectJSON map[string]interface{}
  16. if err = json.Unmarshal(body, &inspectJSON); err != nil {
  17. c.Fatalf("unable to unmarshal body for latest version: %v", err)
  18. }
  19. keys := []string{"State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "ExecDriver", "MountLabel", "ProcessLabel", "Volumes", "VolumesRW", "GraphDriver"}
  20. keys = append(keys, "Id")
  21. for _, key := range keys {
  22. if _, ok := inspectJSON[key]; !ok {
  23. c.Fatalf("%s does not exist in response for latest version", key)
  24. }
  25. }
  26. //Issue #6830: type not properly converted to JSON/back
  27. if _, ok := inspectJSON["Path"].(bool); ok {
  28. c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
  29. }
  30. }