Exemple #1
0
 def test_env_nonexistent_file(self):
     options = {'env_file': 'nonexistent.env'}
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.make_service_dict('foo', options,
                                          'tests/fixtures/env'),
     )
Exemple #2
0
 def test_absolute_path(self):
     service_dict = config.make_service_dict(
         'abspath',
         {'build': self.abs_context_path},
         working_dir='tests/fixtures/build-path'
     )
     self.assertEquals(service_dict['build'], self.abs_context_path)
Exemple #3
0
    def test_resolve_environment(self):
        os.environ['FILE_DEF'] = 'E1'
        os.environ['FILE_DEF_EMPTY'] = 'E2'
        os.environ['ENV_DEF'] = 'E3'

        service_dict = config.make_service_dict(
            'foo',
            {
                'environment': {
                    'FILE_DEF': 'F1',
                    'FILE_DEF_EMPTY': '',
                    'ENV_DEF': None,
                    'NO_DEF': None
                },
            },
        )

        self.assertEqual(
            service_dict['environment'],
            {
                'FILE_DEF': 'F1',
                'FILE_DEF_EMPTY': '',
                'ENV_DEF': 'E3',
                'NO_DEF': ''
            },
        )
Exemple #4
0
 def load_config():
     return config.make_service_dict('myweb', {
         'extends': {
             'file': 'whatever',
             'service': 'web',
         }
     }, '.')
Exemple #5
0
 def test_nonexistent_path(self):
     options = {'build': 'nonexistent.path'}
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.make_service_dict('foo', options,
                                          'tests/fixtures/build-path'),
     )
Exemple #6
0
    def test_resolve_path(self):
        os.environ['HOSTENV'] = '/tmp'
        os.environ['CONTAINERENV'] = '/host/tmp'

        service_dict = config.make_service_dict(
            'foo',
            {'volumes': ['$HOSTENV:$CONTAINERENV']},
            working_dir="tests/fixtures/env"
        )
        self.assertEqual(set(service_dict['volumes']), set(['/tmp:/host/tmp']))

        service_dict = config.make_service_dict(
            'foo',
            {'volumes': ['/opt${HOSTENV}:/opt${CONTAINERENV}']},
            working_dir="tests/fixtures/env"
        )
        self.assertEqual(set(service_dict['volumes']), set(['/opt/tmp:/opt/host/tmp']))
Exemple #7
0
 def test_resolve_environment_from_file(self):
     os.environ["FILE_DEF"] = "E1"
     os.environ["FILE_DEF_EMPTY"] = "E2"
     os.environ["ENV_DEF"] = "E3"
     service_dict = config.make_service_dict("foo", {"env_file": "resolve.env"}, "tests/fixtures/env")
     self.assertEqual(
         service_dict["environment"], {"FILE_DEF": "F1", "FILE_DEF_EMPTY": "", "ENV_DEF": "E3", "NO_DEF": ""}
     )
Exemple #8
0
 def test_relative_path(self):
     relative_build_path = '../build-ctx/'
     service_dict = config.make_service_dict(
         'relpath',
         {'build': relative_build_path},
         working_dir='tests/fixtures/build-path'
     )
     self.assertEquals(service_dict['build'], self.abs_context_path)
Exemple #9
0
 def test_env_from_file(self):
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': 'one.env'},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {'ONE': '2', 'TWO': '1', 'THREE': '3', 'FOO': 'bar'},
     )
Exemple #10
0
 def test_env_from_multiple_files(self):
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': ['one.env', 'two.env']},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {'ONE': '2', 'TWO': '1', 'THREE': '3', 'FOO': 'baz', 'DOO': 'dah'},
     )
Exemple #11
0
    def create_service(self, name, **kwargs):
        if 'image' not in kwargs and 'build' not in kwargs:
            kwargs['image'] = 'busybox:latest'

        if 'command' not in kwargs:
            kwargs['command'] = ["top"]

        return Service(project='composetest',
                       client=self.client,
                       **make_service_dict(name, kwargs, working_dir='.'))
Exemple #12
0
    def create_service(self, name, **kwargs):
        kwargs['image'] = kwargs.pop('image', 'busybox:latest')

        if 'command' not in kwargs:
            kwargs['command'] = ["/bin/sleep", "300"]

        return Service(
            project='composetest',
            client=self.client,
            **make_service_dict(name, kwargs, working_dir='.')
        )
Exemple #13
0
    def test_resolve_environment(self):
        os.environ["FILE_DEF"] = "E1"
        os.environ["FILE_DEF_EMPTY"] = "E2"
        os.environ["ENV_DEF"] = "E3"

        service_dict = config.make_service_dict(
            "foo", {"environment": {"FILE_DEF": "F1", "FILE_DEF_EMPTY": "", "ENV_DEF": None, "NO_DEF": None}}
        )

        self.assertEqual(
            service_dict["environment"], {"FILE_DEF": "F1", "FILE_DEF_EMPTY": "", "ENV_DEF": "E3", "NO_DEF": ""}
        )
Exemple #14
0
    def create_service(self, name, **kwargs):
        if 'image' not in kwargs and 'build' not in kwargs:
            kwargs['image'] = 'busybox:latest'

        if 'command' not in kwargs:
            kwargs['command'] = ["top"]

        return Service(
            project='composetest',
            client=self.client,
            **make_service_dict(name, kwargs, working_dir='.')
        )
Exemple #15
0
 def test_resolve_environment_from_file(self):
     os.environ['FILE_DEF'] = 'E1'
     os.environ['FILE_DEF_EMPTY'] = 'E2'
     os.environ['ENV_DEF'] = 'E3'
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': 'resolve.env'},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''},
     )
Exemple #16
0
 def test_env_from_file(self):
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': 'one.env'},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {
             'ONE': '2',
             'TWO': '1',
             'THREE': '3',
             'FOO': 'bar'
         },
     )
Exemple #17
0
 def test_env_from_multiple_files(self):
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': ['one.env', 'two.env']},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {
             'ONE': '2',
             'TWO': '1',
             'THREE': '3',
             'FOO': 'baz',
             'DOO': 'dah'
         },
     )
Exemple #18
0
 def test_resolve_environment_from_file(self):
     os.environ['FILE_DEF'] = 'E1'
     os.environ['FILE_DEF_EMPTY'] = 'E2'
     os.environ['ENV_DEF'] = 'E3'
     service_dict = config.make_service_dict(
         'foo',
         {'env_file': 'resolve.env'},
         'tests/fixtures/env',
     )
     self.assertEqual(
         service_dict['environment'],
         {
             'FILE_DEF': 'F1',
             'FILE_DEF_EMPTY': '',
             'ENV_DEF': 'E3',
             'NO_DEF': ''
         },
     )
Exemple #19
0
    def test_extends_validation(self):
        dictionary = {'extends': None}
        load_config = lambda: config.make_service_dict(
            'myweb', dictionary, working_dir='tests/fixtures/extends')

        self.assertRaisesRegexp(config.ConfigurationError, 'dictionary',
                                load_config)

        dictionary['extends'] = {}
        self.assertRaises(config.ConfigurationError, load_config)

        dictionary['extends']['file'] = 'common.yml'
        self.assertRaisesRegexp(config.ConfigurationError, 'service',
                                load_config)

        dictionary['extends']['service'] = 'web'
        self.assertIsInstance(load_config(), dict)

        dictionary['extends']['what'] = 'is this'
        self.assertRaisesRegexp(config.ConfigurationError, 'what', load_config)
Exemple #20
0
    def test_resolve_environment(self):
        os.environ['FILE_DEF'] = 'E1'
        os.environ['FILE_DEF_EMPTY'] = 'E2'
        os.environ['ENV_DEF'] = 'E3'

        service_dict = config.make_service_dict(
            'foo', {
                'environment': {
                    'FILE_DEF': 'F1',
                    'FILE_DEF_EMPTY': '',
                    'ENV_DEF': None,
                    'NO_DEF': None
                },
            },
        )

        self.assertEqual(
            service_dict['environment'],
            {'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''},
        )
Exemple #21
0
 def load_config():
     return config.make_service_dict(
         'myweb', dictionary, working_dir='tests/fixtures/extends')
Exemple #22
0
 def test_volume_binding_with_home(self):
     os.environ["HOME"] = "/home/user"
     d = config.make_service_dict("foo", {"volumes": ["~:/container/path"]}, working_dir=".")
     self.assertEqual(d["volumes"], ["/home/user:/container/path"])
Exemple #23
0
 def load_config():
     return config.make_service_dict('myweb', dictionary, working_dir='tests/fixtures/extends')
Exemple #24
0
 def test_env_nonexistent_file(self):
     options = {'env_file': 'nonexistent.env'}
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.make_service_dict('foo', options, 'tests/fixtures/env'),
     )
Exemple #25
0
 def test_env_from_file(self):
     service_dict = config.make_service_dict("foo", {"env_file": "one.env"}, "tests/fixtures/env")
     self.assertEqual(service_dict["environment"], {"ONE": "2", "TWO": "1", "THREE": "3", "FOO": "bar"})
Exemple #26
0
 def test_volume_binding_with_home(self):
     os.environ['HOME'] = '/home/user'
     d = config.make_service_dict('foo', {'volumes': ['~:/container/path']},
                                  working_dir='.')
     self.assertEqual(d['volumes'], ['/home/user:/container/path'])
Exemple #27
0
 def test_relative_path(self):
     relative_build_path = '../build-ctx/'
     service_dict = config.make_service_dict(
         'relpath', {'build': relative_build_path},
         working_dir='tests/fixtures/build-path')
     self.assertEquals(service_dict['build'], self.abs_context_path)
Exemple #28
0
 def test_remove_explicit_value(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {'labels': ['foo=1', 'bar=2']}),
         config.make_service_dict('foo', {'labels': ['bar']}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '1', 'bar': ''})
Exemple #29
0
 def test_no_base(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {}),
         config.make_service_dict('foo', {'labels': ['foo=2']}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '2'})
Exemple #30
0
 def test_volume_binding_with_environ(self):
     os.environ["VOLUME_PATH"] = "/host/path"
     d = config.make_service_dict("foo", {"volumes": ["${VOLUME_PATH}:/container/path"]}, working_dir=".")
     self.assertEqual(d["volumes"], ["/host/path:/container/path"])
Exemple #31
0
 def load_config():
     return config.make_service_dict("myweb", dictionary, working_dir="tests/fixtures/extends")
Exemple #32
0
 def test_volume_binding_with_home(self):
     os.environ['HOME'] = '/home/user'
     d = config.make_service_dict('foo', {'volumes': ['~:/container/path']}, working_dir='.')
     self.assertEqual(d['volumes'], ['/home/user:/container/path'])
Exemple #33
0
 def load_config():
     return config.make_service_dict("myweb", {"extends": {"file": "whatever", "service": "web"}}, ".")
Exemple #34
0
 def load_config():
     return config.make_service_dict(
         'myweb', {'extends': {
             'file': 'whatever',
             'service': 'web',
         }}, '.')
Exemple #35
0
 def test_volume_binding_with_environ(self):
     os.environ['VOLUME_PATH'] = '/host/path'
     d = config.make_service_dict(
         'foo', {'volumes': ['${VOLUME_PATH}:/container/path']},
         working_dir='.')
     self.assertEqual(d['volumes'], ['/host/path:/container/path'])
Exemple #36
0
 def test_env_nonexistent_file(self):
     options = {"env_file": "nonexistent.env"}
     self.assertRaises(
         config.ConfigurationError, lambda: config.make_service_dict("foo", options, "tests/fixtures/env")
     )
Exemple #37
0
 def test_absolute_path(self):
     service_dict = config.make_service_dict(
         'abspath', {'build': self.abs_context_path},
         working_dir='tests/fixtures/build-path')
     self.assertEquals(service_dict['build'], self.abs_context_path)
Exemple #38
0
 def test_remove_explicit_value(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {'labels': ['foo=1', 'bar=2']}),
         config.make_service_dict('foo', {'labels': ['bar']}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '1', 'bar': ''})
Exemple #39
0
 def test_no_base(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {}),
         config.make_service_dict('foo', {'labels': ['foo=2']}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '2'})
Exemple #40
0
 def test_config_validation(self):
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.make_service_dict('foo', {'port': ['8000']})
     )
     config.make_service_dict('foo', {'ports': ['8000']})
Exemple #41
0
 def test_config_validation(self):
     self.assertRaises(config.ConfigurationError, lambda: config.make_service_dict("foo", {"port": ["8000"]}))
     config.make_service_dict("foo", {"ports": ["8000"]})
Exemple #42
0
 def test_absolute_path(self):
     service_dict = config.make_service_dict(
         "abspath", {"build": self.abs_context_path}, working_dir="tests/fixtures/build-path"
     )
     self.assertEquals(service_dict["build"], self.abs_context_path)
Exemple #43
0
 def test_no_override(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {'labels': ['foo=1', 'bar']}),
         config.make_service_dict('foo', {}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '1', 'bar': ''})
Exemple #44
0
 def test_config_validation(self):
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.make_service_dict('foo', {'port': ['8000']}))
     config.make_service_dict('foo', {'ports': ['8000']})
Exemple #45
0
 def test_env_from_multiple_files(self):
     service_dict = config.make_service_dict("foo", {"env_file": ["one.env", "two.env"]}, "tests/fixtures/env")
     self.assertEqual(
         service_dict["environment"], {"ONE": "2", "TWO": "1", "THREE": "3", "FOO": "baz", "DOO": "dah"}
     )
Exemple #46
0
 def test_volume_binding_with_environ(self):
     os.environ['VOLUME_PATH'] = '/host/path'
     d = config.make_service_dict('foo', {'volumes': ['${VOLUME_PATH}:/container/path']}, working_dir='.')
     self.assertEqual(d['volumes'], ['/host/path:/container/path'])
Exemple #47
0
 def test_no_override(self):
     service_dict = config.merge_service_dicts(
         config.make_service_dict('foo', {'labels': ['foo=1', 'bar']}),
         config.make_service_dict('foo', {}),
     )
     self.assertEqual(service_dict['labels'], {'foo': '1', 'bar': ''})
Exemple #48
0
 def test_relative_path(self):
     relative_build_path = "../build-ctx/"
     service_dict = config.make_service_dict(
         "relpath", {"build": relative_build_path}, working_dir="tests/fixtures/build-path"
     )
     self.assertEquals(service_dict["build"], self.abs_context_path)