docker_api_inspect_test.go 1.4 KB

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