@@ -180,3 +180,52 @@ def test_create_with_aliases(self):
180180 self .assertEqual (
181181 container_data ['NetworkSettings' ]['Networks' ][net_name ]['Aliases' ],
182182 ['foo' , 'bar' ])
183+
184+ @requires_api_version ('1.22' )
185+ def test_create_with_links (self ):
186+ net_name , net_id = self .create_network ()
187+
188+ container = self .create_and_start (
189+ host_config = self .client .create_host_config (network_mode = net_name ),
190+ networking_config = self .client .create_networking_config ({
191+ net_name : self .client .create_endpoint_config (
192+ links = [('docker-py-test-upstream' , 'bar' )],
193+ ),
194+ }),
195+ )
196+
197+ container_data = self .client .inspect_container (container )
198+ self .assertEqual (
199+ container_data ['NetworkSettings' ]['Networks' ][net_name ]['Links' ],
200+ ['docker-py-test-upstream:bar' ])
201+
202+ self .create_and_start (
203+ name = 'docker-py-test-upstream' ,
204+ host_config = self .client .create_host_config (network_mode = net_name ),
205+ )
206+
207+ self .execute (container , ['nslookup' , 'bar' ])
208+
209+ @requires_api_version ('1.22' )
210+ def test_connect_with_links (self ):
211+ net_name , net_id = self .create_network ()
212+
213+ container = self .create_and_start (
214+ host_config = self .client .create_host_config (network_mode = net_name ))
215+
216+ self .client .disconnect_container_from_network (container , net_name )
217+ self .client .connect_container_to_network (
218+ container , net_name ,
219+ links = [('docker-py-test-upstream' , 'bar' )])
220+
221+ container_data = self .client .inspect_container (container )
222+ self .assertEqual (
223+ container_data ['NetworkSettings' ]['Networks' ][net_name ]['Links' ],
224+ ['docker-py-test-upstream:bar' ])
225+
226+ self .create_and_start (
227+ name = 'docker-py-test-upstream' ,
228+ host_config = self .client .create_host_config (network_mode = net_name ),
229+ )
230+
231+ self .execute (container , ['nslookup' , 'bar' ])
0 commit comments