예제 #1
0
    def test_mapping_with_name(self):
        templates = ConfigTemplates()

        template = templates.load('instances/tags')
        overrides = {'tags.required': True}
        templates.apply_overrides(template, overrides)
        assert not overrides

        assert template.get('required') is True
예제 #2
0
    def test_primitive_recurse(self):
        templates = ConfigTemplates()

        template = templates.load('instances/http')
        errors = templates.apply_overrides(template, {'proxy.description.foo.foo': 'bar'})

        assert len(errors) == 1
        assert errors[0] == 'Template override `proxy.description` does not refer to a mapping'
예제 #3
0
    def test_list_not_found_root(self):
        templates = ConfigTemplates()

        template = templates.load('instances/http')
        errors = templates.apply_overrides(template, {'foo': 'bar'})

        assert len(errors) == 1
        assert errors[0] == 'Template override has no named mapping `foo`'
예제 #4
0
    def test_list_not_found(self):
        templates = ConfigTemplates()

        template = templates.load('instances/http')
        errors = templates.apply_overrides(template, {'proxy.value.properties.foo.foo': 'bar'})

        assert len(errors) == 1
        assert errors[0] == 'Template override `proxy.value.properties` has no named mapping `foo`'
예제 #5
0
    def test_mapping_with_branches(self):
        templates = ConfigTemplates()

        template = templates.load('init_config/tags.value')
        errors = templates.apply_overrides(template, {'example': ['foo', 'bar']})
        assert not errors

        assert template == {'example': ['foo', 'bar'], 'type': 'array', 'items': {'type': 'string'}}
예제 #6
0
    def test_list_with_branches(self):
        templates = ConfigTemplates()

        template = templates.load('instances/http.skip_proxy')
        errors = templates.apply_overrides(template, {'description': 'foobar'})
        assert not errors

        assert template == {
            'name': 'skip_proxy',
            'value': {'example': False, 'type': 'boolean'},
            'description': 'foobar',
        }
예제 #7
0
    def test_list_replace(self):
        templates = ConfigTemplates()

        original_template = templates.load('instances/http')
        index = next(i for i, item in enumerate(original_template) if item.get('name') == 'skip_proxy')  # no cov

        template = templates.load('instances/http')
        errors = templates.apply_overrides(template, {'skip_proxy': 'foobar'})
        assert not errors

        assert 'foobar' in template
        assert template.index('foobar') == index
        template.remove('foobar')

        for item in template:
            assert item.get('name') != 'skip_proxy'
예제 #8
0
    def test_mapping(self):
        templates = ConfigTemplates()

        template = templates.load('init_config/tags')
        errors = templates.apply_overrides(template, {'value.example': ['foo', 'bar']})
        assert not errors

        assert template == {
            'name': 'tags',
            'value': {'example': ['foo', 'bar'], 'type': 'array', 'items': {'type': 'string'}},
            'description': (
                'A list of tags to attach to every metric and service check emitted by this integration.\n'
                '\n'
                'Learn more about tagging at https://docs.datadoghq.com/tagging\n'
            ),
        }