Exemple #1
0
def test_url_is_suffixed(registry, resource, decorator, id, field, exp_url):
    @decorator(*resource, id=id, field=field, registry=registry)
    def fn(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={'url': 'https://hostname/p1/p2'})

    assert len(webhooks) == 1
    assert webhooks[0]['clientConfig']['url'] == exp_url
Exemple #2
0
def test_irrelevant_resources_are_ignored(registry, resource, decorator):
    @decorator(*resource, registry=registry)
    def fn(**_):
        pass

    irrelevant_resource = Resource('grp', 'vers', 'plural')
    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[irrelevant_resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert len(webhooks[0]['rules']) == 0
Exemple #3
0
def test_name_is_normalised(registry, resource, decorator, id, field,
                            exp_name):
    @decorator(*resource, id=id, field=field, registry=registry)
    def fn(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert webhooks[0]['name'] == exp_name
Exemple #4
0
def test_path_is_suffixed(registry, resource, decorator, id, field, exp_path):
    @decorator(*resource, id=id, field=field, registry=registry)
    def fn(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={'service': {
                                  'path': 'p1/p2'
                              }})

    assert len(webhooks) == 1
    assert webhooks[0]['clientConfig']['service']['path'] == exp_path
Exemple #5
0
def test_labels_specific_filter(registry, resource, decorator, label_value,
                                exp_expr):
    @decorator(*resource, registry=registry, labels={'lbl': label_value})
    def fn(**_):
        pass

    irrelevant_resource = Resource('grp', 'vers', 'plural')
    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[irrelevant_resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert webhooks[0]['objectSelector'] == {'matchExpressions': [exp_expr]}
Exemple #6
0
def test_flat_options_are_mapped(registry, resource, decorator, opts, key,
                                 val):
    @decorator(*resource, registry=registry, **opts)
    def fn(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert webhooks[0][key] == val
    assert webhooks[0]['matchPolicy'] == 'Equivalent'
    assert webhooks[0]['timeoutSeconds'] == 30
    assert webhooks[0]['admissionReviewVersions'] == ['v1', 'v1beta1']
Exemple #7
0
def test_labels_callable_filter(registry, resource, decorator):
    @decorator(*resource,
               registry=registry,
               labels={
                   'lbl': lambda *_, **__: None
               })
    def fn(**_):
        pass

    irrelevant_resource = Resource('grp', 'vers', 'plural')
    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[irrelevant_resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert webhooks[0]['objectSelector'] is None
Exemple #8
0
def test_multiple_handlers(registry, resource, decorator):
    @decorator(*resource, registry=registry)
    def fn1(**_):
        pass

    @decorator(*resource, registry=registry)
    def fn2(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 2
    assert len(webhooks[0]['rules']) == 1
    assert len(webhooks[1]['rules']) == 1
Exemple #9
0
def test_rule_options_are_mapped(registry, resource, decorator, opts, key,
                                 val):
    @decorator(*resource, registry=registry, **opts)
    def fn(**_):
        pass

    webhooks = build_webhooks(registry._resource_webhooks.get_all_handlers(),
                              resources=[resource],
                              name_suffix='sfx',
                              client_config={})

    assert len(webhooks) == 1
    assert len(webhooks[0]['rules']) == 1
    assert webhooks[0]['rules'][0][key] == val
    assert webhooks[0]['rules'][0]['scope'] == '*'
    assert webhooks[0]['rules'][0]['apiGroups'] == [resource.group]
    assert webhooks[0]['rules'][0]['apiVersions'] == [resource.version]
    assert webhooks[0]['rules'][0]['resources'] == [resource.plural]