github.com/wulonghui/docker@v1.8.0-rc2/integration-cli/docker_api_inspect_test.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"net/http"
     7  	"strings"
     8  
     9  	"github.com/go-check/check"
    10  )
    11  
    12  func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
    13  	out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
    14  
    15  	cleanedContainerID := strings.TrimSpace(out)
    16  	keysBase := []string{"Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings",
    17  		"ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "ExecDriver", "MountLabel", "ProcessLabel", "GraphDriver"}
    18  
    19  	cases := []struct {
    20  		version string
    21  		keys    []string
    22  	}{
    23  		{"1.20", append(keysBase, "Mounts")},
    24  		{"1.19", append(keysBase, "Volumes", "VolumesRW")},
    25  	}
    26  
    27  	for _, cs := range cases {
    28  		endpoint := fmt.Sprintf("/v%s/containers/%s/json", cs.version, cleanedContainerID)
    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 version %s: %v", cs.version, err)
    37  		}
    38  
    39  		for _, key := range cs.keys {
    40  			if _, ok := inspectJSON[key]; !ok {
    41  				c.Fatalf("%s does not exist in response for version %s", key, cs.version)
    42  			}
    43  		}
    44  
    45  		//Issue #6830: type not properly converted to JSON/back
    46  		if _, ok := inspectJSON["Path"].(bool); ok {
    47  			c.Fatalf("Path of `true` should not be converted to boolean `true` via JSON marshalling")
    48  		}
    49  	}
    50  }