Beispiel #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'),
     )
Beispiel #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)
Beispiel #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': ''
            },
        )
Beispiel #4
0
 def load_config():
     return config.make_service_dict('myweb', {
         'extends': {
             'file': 'whatever',
             'service': 'web',
         }
     }, '.')
Beispiel #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'),
     )
Beispiel #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']))
Beispiel #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": ""}
     )
Beispiel #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)
Beispiel #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'},
     )
Beispiel #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'},
     )
Beispiel #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='.'))
Beispiel #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='.')
        )
Beispiel #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": ""}
        )
Beispiel #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='.')
        )
Beispiel #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': ''},
     )
Beispiel #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'
         },
     )
Beispiel #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'
         },
     )
Beispiel #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': ''
         },
     )
Beispiel #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)
Beispiel #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': ''},
        )
Beispiel #21
0
 def load_config():
     return config.make_service_dict(
         'myweb', dictionary, working_dir='tests/fixtures/extends')
Beispiel #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"])
Beispiel #23
0
 def load_config():
     return config.make_service_dict('myweb', dictionary, working_dir='tests/fixtures/extends')
Beispiel #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'),
     )
Beispiel #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"})
Beispiel #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'])
Beispiel #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)
Beispiel #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': ''})
Beispiel #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'})
Beispiel #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"])
Beispiel #31
0
 def load_config():
     return config.make_service_dict("myweb", dictionary, working_dir="tests/fixtures/extends")
Beispiel #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'])
Beispiel #33
0
 def load_config():
     return config.make_service_dict("myweb", {"extends": {"file": "whatever", "service": "web"}}, ".")
Beispiel #34
0
 def load_config():
     return config.make_service_dict(
         'myweb', {'extends': {
             'file': 'whatever',
             'service': 'web',
         }}, '.')
Beispiel #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'])
Beispiel #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")
     )
Beispiel #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)
Beispiel #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': ''})
Beispiel #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'})
Beispiel #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']})
Beispiel #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"]})
Beispiel #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)
Beispiel #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': ''})
Beispiel #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']})
Beispiel #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"}
     )
Beispiel #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'])
Beispiel #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': ''})
Beispiel #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)