|
9 | 9 | import tempfile
|
10 | 10 | import unittest
|
11 | 11 |
|
| 12 | +from py.test import ensuretemp |
| 13 | +from pytest import mark |
| 14 | + |
12 | 15 | from docker import auth, errors
|
13 | 16 |
|
14 | 17 | try:
|
@@ -269,6 +272,56 @@ def test_resolve_registry_and_auth_unauthenticated_registry(self):
|
269 | 272 | )
|
270 | 273 |
|
271 | 274 |
|
| 275 | +class FindConfigFileTest(unittest.TestCase): |
| 276 | + def tmpdir(self, name): |
| 277 | + tmpdir = ensuretemp(name) |
| 278 | + self.addCleanup(tmpdir.remove) |
| 279 | + return tmpdir |
| 280 | + |
| 281 | + def test_find_config_fallback(self): |
| 282 | + tmpdir = self.tmpdir('test_find_config_fallback') |
| 283 | + |
| 284 | + with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}): |
| 285 | + assert auth.find_config_file() is None |
| 286 | + |
| 287 | + def test_find_config_from_explicit_path(self): |
| 288 | + tmpdir = self.tmpdir('test_find_config_from_explicit_path') |
| 289 | + config_path = tmpdir.ensure('my-config-file.json') |
| 290 | + |
| 291 | + assert auth.find_config_file(str(config_path)) == str(config_path) |
| 292 | + |
| 293 | + def test_find_config_from_environment(self): |
| 294 | + tmpdir = self.tmpdir('test_find_config_from_environment') |
| 295 | + config_path = tmpdir.ensure('config.json') |
| 296 | + |
| 297 | + with mock.patch.dict(os.environ, {'DOCKER_CONFIG': str(tmpdir)}): |
| 298 | + assert auth.find_config_file() == str(config_path) |
| 299 | + |
| 300 | + @mark.skipif("sys.platform == 'win32'") |
| 301 | + def test_find_config_from_home_posix(self): |
| 302 | + tmpdir = self.tmpdir('test_find_config_from_home_posix') |
| 303 | + config_path = tmpdir.ensure('.docker', 'config.json') |
| 304 | + |
| 305 | + with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}): |
| 306 | + assert auth.find_config_file() == str(config_path) |
| 307 | + |
| 308 | + @mark.skipif("sys.platform == 'win32'") |
| 309 | + def test_find_config_from_home_legacy_name(self): |
| 310 | + tmpdir = self.tmpdir('test_find_config_from_home_legacy_name') |
| 311 | + config_path = tmpdir.ensure('.dockercfg') |
| 312 | + |
| 313 | + with mock.patch.dict(os.environ, {'HOME': str(tmpdir)}): |
| 314 | + assert auth.find_config_file() == str(config_path) |
| 315 | + |
| 316 | + @mark.skipif("sys.platform != 'win32'") |
| 317 | + def test_find_config_from_home_windows(self): |
| 318 | + tmpdir = self.tmpdir('test_find_config_from_home_windows') |
| 319 | + config_path = tmpdir.ensure('.docker', 'config.json') |
| 320 | + |
| 321 | + with mock.patch.dict(os.environ, {'USERPROFILE': str(tmpdir)}): |
| 322 | + assert auth.find_config_file() == str(config_path) |
| 323 | + |
| 324 | + |
272 | 325 | class LoadConfigTest(unittest.TestCase):
|
273 | 326 | def test_load_config_no_file(self):
|
274 | 327 | folder = tempfile.mkdtemp()
|
|
0 commit comments