|
10 | 10 | EndpointConfig, HostConfig, IPAMConfig, IPAMPool, LogConfig, Mount, Ulimit,
|
11 | 11 | )
|
12 | 12 |
|
| 13 | +try: |
| 14 | + from unittest import mock |
| 15 | +except: |
| 16 | + import mock |
| 17 | + |
13 | 18 |
|
14 | 19 | def create_host_config(*args, **kwargs):
|
15 | 20 | return HostConfig(*args, **kwargs)
|
@@ -258,28 +263,48 @@ def test_create_ipam_config(self):
|
258 | 263 | class TestMounts(unittest.TestCase):
|
259 | 264 | def test_parse_mount_string_ro(self):
|
260 | 265 | 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) |
| 266 | + assert mount['Source'] == "/foo/bar" |
| 267 | + assert mount['Target'] == "/baz" |
| 268 | + assert mount['ReadOnly'] is True |
264 | 269 |
|
265 | 270 | def test_parse_mount_string_rw(self):
|
266 | 271 | 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) |
| 272 | + assert mount['Source'] == "/foo/bar" |
| 273 | + assert mount['Target'] == "/baz" |
| 274 | + assert not mount['ReadOnly'] |
270 | 275 |
|
271 | 276 | def test_parse_mount_string_short_form(self):
|
272 | 277 | 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) |
| 278 | + assert mount['Source'] == "/foo/bar" |
| 279 | + assert mount['Target'] == "/baz" |
| 280 | + assert not mount['ReadOnly'] |
276 | 281 |
|
277 | 282 | def test_parse_mount_string_no_source(self):
|
278 | 283 | 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) |
| 284 | + assert mount['Source'] is None |
| 285 | + assert mount['Target'] == "foo/bar" |
| 286 | + assert not mount['ReadOnly'] |
282 | 287 |
|
283 | 288 | def test_parse_mount_string_invalid(self):
|
284 | 289 | with pytest.raises(InvalidArgument):
|
285 | 290 | Mount.parse_mount_string("foo:bar:baz:rw")
|
| 291 | + |
| 292 | + def test_parse_mount_named_volume(self): |
| 293 | + mount = Mount.parse_mount_string("foobar:/baz") |
| 294 | + assert mount['Source'] == 'foobar' |
| 295 | + assert mount['Target'] == '/baz' |
| 296 | + assert mount['Type'] == 'volume' |
| 297 | + |
| 298 | + def test_parse_mount_bind(self): |
| 299 | + mount = Mount.parse_mount_string('/foo/bar:/baz') |
| 300 | + assert mount['Source'] == "/foo/bar" |
| 301 | + assert mount['Target'] == "/baz" |
| 302 | + assert mount['Type'] == 'bind' |
| 303 | + |
| 304 | + @pytest.mark.xfail |
| 305 | + def test_parse_mount_bind_windows(self): |
| 306 | + with mock.patch('docker.types.services.IS_WINDOWS_PLATFORM', True): |
| 307 | + mount = Mount.parse_mount_string('C:/foo/bar:/baz') |
| 308 | + assert mount['Source'] == "C:/foo/bar" |
| 309 | + assert mount['Target'] == "/baz" |
| 310 | + assert mount['Type'] == 'bind' |
0 commit comments