github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/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  	// test on json marshal version
    22  	// and latest version
    23  	testVersions := []string{"v1.11", "latest"}
    24  
    25  	for _, testVersion := range testVersions {
    26  		endpoint := "/containers/" + cleanedContainerID + "/json"
    27  		if testVersion != "latest" {
    28  			endpoint = "/" + testVersion + endpoint
    29  		}
    30  		status, body, err := sockRequest("GET", endpoint, nil)
    31  		c.Assert(status, check.Equals, http.StatusOK)
    32  		c.Assert(err, check.IsNil)
    33  
    34  		var inspectJSON map[string]interface{}
    35  		if err = json.Unmarshal(body, &inspectJSON); err != nil {
    36  			c.Fatalf("unable to unmarshal body for %s version: %v", testVersion, err)
    37  		}
    38  
    39  		keys := []string{"State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings", "ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "ExecDriver", "MountLabel", "ProcessLabel", "Volumes", "VolumesRW"}
    40  
    41  		if testVersion == "v1.11" {
    42  			keys = append(keys, "ID")
    43  		} else {
    44  			keys = append(keys, "Id")
    45  		}
    46  
    47  		for _, key := range keys {
    48  			if _, ok := inspectJSON[key]; !ok {
    49  				c.Fatalf("%s does not exist in response for %s version", key, testVersion)
    50  			}
    51  		}
    52  		//Issue #6830: type not properly converted to JSON/back
    53  		if _, ok := inspectJSON["Path"].(bool); ok {
    54  			c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
    55  		}
    56  	}
    57  }