|
5 | 5 | import pytest
|
6 | 6 |
|
7 | 7 | from docker.constants import DEFAULT_DOCKER_API_VERSION
|
8 |
| -from docker.errors import InvalidVersion |
| 8 | +from docker.errors import InvalidArgument, InvalidVersion |
9 | 9 | from docker.types import (
|
10 |
| - EndpointConfig, HostConfig, IPAMConfig, IPAMPool, LogConfig, Ulimit, |
| 10 | + EndpointConfig, HostConfig, IPAMConfig, IPAMPool, LogConfig, Mount, Ulimit, |
11 | 11 | )
|
12 | 12 |
|
13 | 13 |
|
@@ -253,3 +253,33 @@ def test_create_ipam_config(self):
|
253 | 253 | 'IPRange': None,
|
254 | 254 | }]
|
255 | 255 | })
|
| 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") |
0 commit comments