github.com/codemac/docker@v1.2.1-0.20150518222241-6a18412d5b9c/integration-cli/docker_api_inspect_test.go (about)

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