docker_api_inspect_test.go 1.4 KB

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