|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
1 | 3 | import os
|
2 | 4 | import os.path
|
3 | 5 | import shutil
|
4 | 6 | import tempfile
|
5 | 7 |
|
| 8 | +import pytest |
| 9 | +import six |
| 10 | + |
6 | 11 | from docker.client import Client
|
7 | 12 | from docker.constants import DEFAULT_DOCKER_API_VERSION
|
8 | 13 | from docker.errors import DockerException
|
9 | 14 | from docker.utils import (
|
10 | 15 | parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
|
11 | 16 | create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
|
12 |
| - exclude_paths, |
| 17 | + exclude_paths, convert_volume_binds, |
13 | 18 | )
|
14 | 19 | from docker.utils.ports import build_port_bindings, split_port
|
15 | 20 | from docker.auth import resolve_repository_name, resolve_authconfig
|
16 | 21 |
|
17 | 22 | from . import base
|
18 | 23 | from .helpers import make_tree
|
19 | 24 |
|
20 |
| -import pytest |
21 | 25 |
|
22 | 26 | TEST_CERT_DIR = os.path.join(
|
23 | 27 | os.path.dirname(__file__),
|
@@ -192,6 +196,89 @@ def generate_tempfile(self, file_content=None):
|
192 | 196 | local_tempfile.close()
|
193 | 197 | return local_tempfile.name
|
194 | 198 |
|
| 199 | + def test_convert_volume_binds_empty(self): |
| 200 | + self.assertEqual(convert_volume_binds({}), []) |
| 201 | + self.assertEqual(convert_volume_binds([]), []) |
| 202 | + |
| 203 | + def test_convert_volume_binds_list(self): |
| 204 | + data = ['/a:/a:ro', '/b:/c:z'] |
| 205 | + self.assertEqual(convert_volume_binds(data), data) |
| 206 | + |
| 207 | + def test_convert_volume_binds_complete(self): |
| 208 | + data = { |
| 209 | + '/mnt/vol1': { |
| 210 | + 'bind': '/data', |
| 211 | + 'mode': 'ro' |
| 212 | + } |
| 213 | + } |
| 214 | + self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:ro']) |
| 215 | + |
| 216 | + def test_convert_volume_binds_compact(self): |
| 217 | + data = { |
| 218 | + '/mnt/vol1': '/data' |
| 219 | + } |
| 220 | + self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:rw']) |
| 221 | + |
| 222 | + def test_convert_volume_binds_no_mode(self): |
| 223 | + data = { |
| 224 | + '/mnt/vol1': { |
| 225 | + 'bind': '/data' |
| 226 | + } |
| 227 | + } |
| 228 | + self.assertEqual(convert_volume_binds(data), ['/mnt/vol1:/data:rw']) |
| 229 | + |
| 230 | + def test_convert_volume_binds_unicode_bytes_input(self): |
| 231 | + if six.PY2: |
| 232 | + expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')] |
| 233 | + |
| 234 | + data = { |
| 235 | + '/mnt/지연': { |
| 236 | + 'bind': '/unicode/박', |
| 237 | + 'mode': 'rw' |
| 238 | + } |
| 239 | + } |
| 240 | + self.assertEqual( |
| 241 | + convert_volume_binds(data), expected |
| 242 | + ) |
| 243 | + else: |
| 244 | + expected = ['/mnt/지연:/unicode/박:rw'] |
| 245 | + |
| 246 | + data = { |
| 247 | + bytes('/mnt/지연', 'utf-8'): { |
| 248 | + 'bind': bytes('/unicode/박', 'utf-8'), |
| 249 | + 'mode': 'rw' |
| 250 | + } |
| 251 | + } |
| 252 | + self.assertEqual( |
| 253 | + convert_volume_binds(data), expected |
| 254 | + ) |
| 255 | + |
| 256 | + def test_convert_volume_binds_unicode_unicode_input(self): |
| 257 | + if six.PY2: |
| 258 | + expected = [unicode('/mnt/지연:/unicode/박:rw', 'utf-8')] |
| 259 | + |
| 260 | + data = { |
| 261 | + unicode('/mnt/지연', 'utf-8'): { |
| 262 | + 'bind': unicode('/unicode/박', 'utf-8'), |
| 263 | + 'mode': 'rw' |
| 264 | + } |
| 265 | + } |
| 266 | + self.assertEqual( |
| 267 | + convert_volume_binds(data), expected |
| 268 | + ) |
| 269 | + else: |
| 270 | + expected = ['/mnt/지연:/unicode/박:rw'] |
| 271 | + |
| 272 | + data = { |
| 273 | + '/mnt/지연': { |
| 274 | + 'bind': '/unicode/박', |
| 275 | + 'mode': 'rw' |
| 276 | + } |
| 277 | + } |
| 278 | + self.assertEqual( |
| 279 | + convert_volume_binds(data), expected |
| 280 | + ) |
| 281 | + |
195 | 282 | def test_parse_repository_tag(self):
|
196 | 283 | self.assertEqual(parse_repository_tag("root"),
|
197 | 284 | ("root", None))
|
|
0 commit comments