@@ -2,11 +2,12 @@ package main
22
33import (
44 "encoding/json"
5- "fmt"
65 "net/http"
76 "strings"
87
98 "github.com/docker/docker/api/types"
9+ "github.com/docker/docker/api/types/versions/v1p20"
10+ "github.com/docker/docker/pkg/integration/checker"
1011 "github.com/docker/docker/pkg/stringutils"
1112 "github.com/go-check/check"
1213)
@@ -23,19 +24,15 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
2324 version string
2425 keys []string
2526 }{
26- {"1 .20" , append (keysBase , "Mounts" )},
27- {"1 .19" , append (keysBase , "Volumes" , "VolumesRW" )},
27+ {"v1 .20" , append (keysBase , "Mounts" )},
28+ {"v1 .19" , append (keysBase , "Volumes" , "VolumesRW" )},
2829 }
2930
3031 for _ , cs := range cases {
31- endpoint := fmt .Sprintf ("/v%s/containers/%s/json" , cs .version , cleanedContainerID )
32-
33- status , body , err := sockRequest ("GET" , endpoint , nil )
34- c .Assert (err , check .IsNil )
35- c .Assert (status , check .Equals , http .StatusOK )
32+ body := getInspectBody (c , cs .version , cleanedContainerID )
3633
3734 var inspectJSON map [string ]interface {}
38- if err = json .Unmarshal (body , & inspectJSON ); err != nil {
35+ if err : = json .Unmarshal (body , & inspectJSON ); err != nil {
3936 c .Fatalf ("unable to unmarshal body for version %s: %v" , cs .version , err )
4037 }
4138
@@ -57,15 +54,12 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriverLegacy(c *check.C) {
5754
5855 cleanedContainerID := strings .TrimSpace (out )
5956
60- cases := []string {"1 .19" , "1 .20" }
57+ cases := []string {"v1 .19" , "v1 .20" }
6158 for _ , version := range cases {
62- endpoint := fmt .Sprintf ("/v%s/containers/%s/json" , version , cleanedContainerID )
63- status , body , err := sockRequest ("GET" , endpoint , nil )
64- c .Assert (err , check .IsNil )
65- c .Assert (status , check .Equals , http .StatusOK )
59+ body := getInspectBody (c , version , cleanedContainerID )
6660
6761 var inspectJSON map [string ]interface {}
68- if err = json .Unmarshal (body , & inspectJSON ); err != nil {
62+ if err : = json .Unmarshal (body , & inspectJSON ); err != nil {
6963 c .Fatalf ("unable to unmarshal body for version %s: %v" , version , err )
7064 }
7165
@@ -85,13 +79,10 @@ func (s *DockerSuite) TestInspectApiContainerVolumeDriver(c *check.C) {
8579
8680 cleanedContainerID := strings .TrimSpace (out )
8781
88- endpoint := fmt .Sprintf ("/v1.21/containers/%s/json" , cleanedContainerID )
89- status , body , err := sockRequest ("GET" , endpoint , nil )
90- c .Assert (err , check .IsNil )
91- c .Assert (status , check .Equals , http .StatusOK )
82+ body := getInspectBody (c , "v1.21" , cleanedContainerID )
9283
9384 var inspectJSON map [string ]interface {}
94- if err = json .Unmarshal (body , & inspectJSON ); err != nil {
85+ if err : = json .Unmarshal (body , & inspectJSON ); err != nil {
9586 c .Fatalf ("unable to unmarshal body for version 1.21: %v" , err )
9687 }
9788
@@ -140,15 +131,12 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
140131
141132 cleanedContainerID := strings .TrimSpace (out )
142133
143- cases := []string {"1 .19" , "1 .20" }
134+ cases := []string {"v1 .19" , "v1 .20" }
144135 for _ , version := range cases {
145- endpoint := fmt .Sprintf ("/v%s/containers/%s/json" , version , cleanedContainerID )
146- status , body , err := sockRequest ("GET" , endpoint , nil )
147- c .Assert (err , check .IsNil )
148- c .Assert (status , check .Equals , http .StatusOK )
136+ body := getInspectBody (c , version , cleanedContainerID )
149137
150138 var inspectJSON map [string ]interface {}
151- if err = json .Unmarshal (body , & inspectJSON ); err != nil {
139+ if err : = json .Unmarshal (body , & inspectJSON ); err != nil {
152140 c .Fatalf ("unable to unmarshal body for version %s: %v" , version , err )
153141 }
154142
@@ -164,3 +152,33 @@ func (s *DockerSuite) TestInspectApiEmptyFieldsInConfigPre121(c *check.C) {
164152 }
165153 }
166154}
155+
156+ func (s * DockerSuite ) TestInspectApiBridgeNetworkSettings120 (c * check.C ) {
157+ out , _ := dockerCmd (c , "run" , "-d" , "busybox" , "true" )
158+
159+ cleanedContainerID := strings .TrimSpace (out )
160+ body := getInspectBody (c , "v1.20" , cleanedContainerID )
161+
162+ var inspectJSON v1p20.ContainerJSON
163+ err := json .Unmarshal (body , & inspectJSON )
164+ c .Assert (err , checker .IsNil )
165+
166+ settings := inspectJSON .NetworkSettings
167+ c .Assert (settings .IPAddress , checker .Not (checker .HasLen ), 0 )
168+ }
169+
170+ func (s * DockerSuite ) TestInspectApiBridgeNetworkSettings121 (c * check.C ) {
171+ out , _ := dockerCmd (c , "run" , "-d" , "busybox" , "true" )
172+ cleanedContainerID := strings .TrimSpace (out )
173+
174+ body := getInspectBody (c , "v1.21" , cleanedContainerID )
175+
176+ var inspectJSON types.ContainerJSON
177+ err := json .Unmarshal (body , & inspectJSON )
178+ c .Assert (err , checker .IsNil )
179+
180+ settings := inspectJSON .NetworkSettings
181+ c .Assert (settings .IPAddress , checker .Not (checker .HasLen ), 0 )
182+ c .Assert (settings .Networks ["bridge" ], checker .Not (checker .IsNil ))
183+ c .Assert (settings .IPAddress , checker .Equals , settings .Networks ["bridge" ].IPAddress )
184+ }
0 commit comments