Skip to content

Commit ab77032

Browse files
committed
Additional parse_mount_string tests
Signed-off-by: Joffrey F <[email protected]>
1 parent 454328d commit ab77032

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

tests/unit/dockertypes_test.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import pytest
66

77
from docker.constants import DEFAULT_DOCKER_API_VERSION
8-
from docker.errors import InvalidVersion
8+
from docker.errors import InvalidArgument, InvalidVersion
99
from docker.types import (
10-
EndpointConfig, HostConfig, IPAMConfig, IPAMPool, LogConfig, Ulimit,
10+
EndpointConfig, HostConfig, IPAMConfig, IPAMPool, LogConfig, Mount, Ulimit,
1111
)
1212

1313

@@ -253,3 +253,33 @@ def test_create_ipam_config(self):
253253
'IPRange': None,
254254
}]
255255
})
256+
257+
258+
class TestMounts(unittest.TestCase):
259+
def test_parse_mount_string_ro(self):
260+
mount = Mount.parse_mount_string("/foo/bar:/baz:ro")
261+
self.assertEqual(mount['Source'], "/foo/bar")
262+
self.assertEqual(mount['Target'], "/baz")
263+
self.assertEqual(mount['ReadOnly'], True)
264+
265+
def test_parse_mount_string_rw(self):
266+
mount = Mount.parse_mount_string("/foo/bar:/baz:rw")
267+
self.assertEqual(mount['Source'], "/foo/bar")
268+
self.assertEqual(mount['Target'], "/baz")
269+
self.assertEqual(mount['ReadOnly'], False)
270+
271+
def test_parse_mount_string_short_form(self):
272+
mount = Mount.parse_mount_string("/foo/bar:/baz")
273+
self.assertEqual(mount['Source'], "/foo/bar")
274+
self.assertEqual(mount['Target'], "/baz")
275+
self.assertEqual(mount['ReadOnly'], False)
276+
277+
def test_parse_mount_string_no_source(self):
278+
mount = Mount.parse_mount_string("foo/bar")
279+
self.assertEqual(mount['Source'], None)
280+
self.assertEqual(mount['Target'], "foo/bar")
281+
self.assertEqual(mount['ReadOnly'], False)
282+
283+
def test_parse_mount_string_invalid(self):
284+
with pytest.raises(InvalidArgument):
285+
Mount.parse_mount_string("foo:bar:baz:rw")

tests/unit/types.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)