17
17
import json
18
18
import io
19
19
import os
20
+ import shutil
20
21
import signal
21
22
import tempfile
22
23
import unittest
27
28
# FIXME: missing tests for
28
29
# export; history; import_image; insert; port; push; tag; get; load
29
30
31
+ DEFAULT_BASE_URL = os .environ .get ('DOCKER_HOST' )
32
+
30
33
31
34
class BaseTestCase (unittest .TestCase ):
32
35
tmp_imgs = []
33
36
tmp_containers = []
37
+ tmp_folders = []
34
38
35
39
def setUp (self ):
36
- self .client = docker .Client (timeout = 5 )
40
+ self .client = docker .Client (base_url = DEFAULT_BASE_URL , timeout = 5 )
37
41
self .tmp_imgs = []
38
42
self .tmp_containers = []
43
+ self .tmp_folders = []
39
44
40
45
def tearDown (self ):
41
46
for img in self .tmp_imgs :
@@ -49,6 +54,8 @@ def tearDown(self):
49
54
self .client .remove_container (container )
50
55
except docker .errors .APIError :
51
56
pass
57
+ for folder in self .tmp_folders :
58
+ shutil .rmtree (folder )
52
59
53
60
#########################
54
61
# INFORMATION TESTS #
@@ -108,7 +115,7 @@ class TestListContainers(BaseTestCase):
108
115
def runTest (self ):
109
116
res0 = self .client .containers (all = True )
110
117
size = len (res0 )
111
- res1 = self .client .create_container ('busybox:latest' , 'true; ' )
118
+ res1 = self .client .create_container ('busybox:latest' , 'true' )
112
119
self .assertIn ('Id' , res1 )
113
120
self .client .start (res1 ['Id' ])
114
121
self .tmp_containers .append (res1 ['Id' ])
@@ -118,7 +125,7 @@ def runTest(self):
118
125
self .assertEqual (len (retrieved ), 1 )
119
126
retrieved = retrieved [0 ]
120
127
self .assertIn ('Command' , retrieved )
121
- self .assertEqual (retrieved ['Command' ], u'true; ' )
128
+ self .assertEqual (retrieved ['Command' ], u'true' )
122
129
self .assertIn ('Image' , retrieved )
123
130
self .assertRegexpMatches (retrieved ['Image' ], r'busybox:.*' )
124
131
self .assertIn ('Status' , retrieved )
@@ -138,7 +145,8 @@ def runTest(self):
138
145
class TestCreateContainerWithBinds (BaseTestCase ):
139
146
def runTest (self ):
140
147
mount_dest = '/mnt'
141
- mount_origin = '/tmp'
148
+ mount_origin = tempfile .mkdtemp ()
149
+ self .tmp_folders .append (mount_origin )
142
150
143
151
filename = 'shared.txt'
144
152
shared_file = os .path .join (mount_origin , filename )
@@ -850,6 +858,7 @@ def runTest(self):
850
858
class TestLoadConfig (BaseTestCase ):
851
859
def runTest (self ):
852
860
folder = tempfile .mkdtemp ()
861
+ self .tmp_folders .append (folder )
853
862
f = open (os .path .join (folder , '.dockercfg' ), 'w' )
854
863
auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
855
864
f .write ('auth = {0}\n ' .format (auth_ ))
@@ -867,6 +876,7 @@ def runTest(self):
867
876
class TestLoadJSONConfig (BaseTestCase ):
868
877
def runTest (self ):
869
878
folder = tempfile .mkdtemp ()
879
+ self .tmp_folders .append (folder )
870
880
f = open (os .path .join (folder , '.dockercfg' ), 'w' )
871
881
auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
872
882
@@ -902,6 +912,6 @@ def runTest(self):
902
912
903
913
904
914
if __name__ == '__main__' :
905
- c = docker .Client ()
915
+ c = docker .Client (base_url = DEFAULT_BASE_URL )
906
916
c .pull ('busybox' )
907
917
unittest .main ()
0 commit comments