@@ -83,6 +83,7 @@ def test_push_image(self, mock_client):
83
83
@mock .patch .dict (os .environ , clear = True )
84
84
@mock .patch ('docker.APIClient' )
85
85
def test_push_image_failure (self , mock_client ):
86
+ """failure on connecting Docker API"""
86
87
self .dc = mock_client
87
88
mock_client ().push .side_effect = Exception
88
89
pusher = build .PushTask (self .conf , self .image )
@@ -96,6 +97,7 @@ def test_push_image_failure(self, mock_client):
96
97
@mock .patch .dict (os .environ , clear = True )
97
98
@mock .patch ('docker.APIClient' )
98
99
def test_push_image_failure_retry (self , mock_client ):
100
+ """failure on connecting Docker API, success on retry"""
99
101
self .dc = mock_client
100
102
mock_client ().push .side_effect = [Exception , []]
101
103
pusher = build .PushTask (self .conf , self .image )
@@ -112,6 +114,44 @@ def test_push_image_failure_retry(self, mock_client):
112
114
self .assertTrue (pusher .success )
113
115
self .assertEqual (build .STATUS_BUILT , self .image .status )
114
116
117
+ @mock .patch ('docker.version' , '3.0.0' )
118
+ @mock .patch .dict (os .environ , clear = True )
119
+ @mock .patch ('docker.APIClient' )
120
+ def test_push_image_failure_error (self , mock_client ):
121
+ """Docker connected, failure to push"""
122
+ self .dc = mock_client
123
+ mock_client ().push .return_value = [{'errorDetail' : {'message' :
124
+ 'mock push fail' }}]
125
+ pusher = build .PushTask (self .conf , self .image )
126
+ pusher .run ()
127
+ mock_client ().push .assert_called_once_with (
128
+ self .image .canonical_name , decode = True , stream = True )
129
+ self .assertFalse (pusher .success )
130
+ self .assertEqual (build .STATUS_PUSH_ERROR , self .image .status )
131
+
132
+ @mock .patch ('docker.version' , '3.0.0' )
133
+ @mock .patch .dict (os .environ , clear = True )
134
+ @mock .patch ('docker.APIClient' )
135
+ def test_push_image_failure_error_retry (self , mock_client ):
136
+ """Docker connected, failure to push, success on retry"""
137
+ self .dc = mock_client
138
+ mock_client ().push .return_value = [{'errorDetail' : {'message' :
139
+ 'mock push fail' }}]
140
+ pusher = build .PushTask (self .conf , self .image )
141
+ pusher .run ()
142
+ mock_client ().push .assert_called_once_with (
143
+ self .image .canonical_name , decode = True , stream = True )
144
+ self .assertFalse (pusher .success )
145
+ self .assertEqual (build .STATUS_PUSH_ERROR , self .image .status )
146
+
147
+ # Try again, this time without exception.
148
+ mock_client ().push .return_value = [{'stream' : 'mock push passes' }]
149
+ pusher .reset ()
150
+ pusher .run ()
151
+ self .assertEqual (2 , mock_client ().push .call_count )
152
+ self .assertTrue (pusher .success )
153
+ self .assertEqual (build .STATUS_BUILT , self .image .status )
154
+
115
155
@mock .patch .dict (os .environ , clear = True )
116
156
@mock .patch ('docker.APIClient' )
117
157
def test_build_image (self , mock_client ):
0 commit comments