Skip to content

Commit cc953cf

Browse files
committed
prune_builds test
Signed-off-by: Joffrey F <[email protected]>
1 parent f2c1ae3 commit cc953cf

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

docker/api/build.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
264264

265265
return self._stream_helper(response, decode=decode)
266266

267+
@utils.minimum_version('1.31')
268+
def prune_builds(self):
269+
"""
270+
Delete the builder cache
271+
272+
Returns:
273+
(dict): A dictionary containing information about the operation's
274+
result. The ``SpaceReclaimed`` key indicates the amount of
275+
bytes of disk space reclaimed.
276+
277+
Raises:
278+
:py:class:`docker.errors.APIError`
279+
If the server returns an error.
280+
"""
281+
url = self._url("/build/prune")
282+
return self._result(self._post(url), True)
283+
267284
def _set_auth_headers(self, headers):
268285
log.debug('Looking for auth config')
269286

@@ -305,22 +322,6 @@ def _set_auth_headers(self, headers):
305322
else:
306323
log.debug('No auth config found')
307324

308-
@utils.minimum_version('1.31')
309-
def prune_build(self):
310-
"""
311-
Delete builder cache
312-
313-
Returns:
314-
(dict): A dict containing
315-
the amount of disk space reclaimed in bytes.
316-
317-
Raises:
318-
:py:class:`docker.errors.APIError`
319-
If the server returns an error.
320-
"""
321-
url = self._url("/build/prune")
322-
return self._result(self._post(url), True)
323-
324325

325326
def process_dockerfile(dockerfile, path):
326327
if not dockerfile:

tests/integration/api_build_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,9 @@ def test_build_in_context_abs_dockerfile(self):
503503
assert sorted(
504504
[b'.', b'..', b'file.txt', b'custom.dockerfile']
505505
) == sorted(lsdata)
506+
507+
@requires_api_version('1.31')
508+
def test_prune_builds(self):
509+
prune_result = self.client.prune_builds()
510+
assert 'SpaceReclaimed' in prune_result
511+
assert isinstance(prune_result['SpaceReclaimed'], int)

0 commit comments

Comments
 (0)