Ejemplo n.º 1
0
def test_initial_population(registry, insights, insights_resources):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=VERBS)
    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    assert insights_resources == {r1}
Ejemplo n.º 2
0
def test_no_ambiguity_in_generic_selector(registry, decorator, caplog,
                                          assert_logs, insights):
    r1 = Resource(group='g1', version='v1', plural='plural', verbs=VERBS)
    r2 = Resource(group='g2', version='v2', plural='plural', verbs=VERBS)

    @decorator(EVERYTHING)
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1, r2])
    assert insights.watched_resources == {r1, r2}
    assert_logs([], prohibited=[r"Ambiguous resources will not be served"])
Ejemplo n.º 3
0
def test_ambiguity_in_specific_selectors(registry, decorator, caplog,
                                         assert_logs, insights):
    r1 = Resource(group='g1', version='v1', plural='plural', verbs=VERBS)
    r2 = Resource(group='g2', version='v2', plural='plural', verbs=VERBS)

    @decorator(plural='plural')
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1, r2])
    assert not insights.watched_resources
    assert not insights.webhook_resources
    assert_logs([r"Ambiguous resources will not be served"])
Ejemplo n.º 4
0
def test_replacing_a_new_group(registry, insights, insights_resources):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=VERBS)
    r2 = Resource(group='group2',
                  version='version2',
                  plural='plural2',
                  verbs=VERBS)
    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    revise_resources(registry=registry,
                     insights=insights,
                     group='group2',
                     resources=[r2])
    assert insights_resources == {r1, r2}
Ejemplo n.º 5
0
def test_corev1_overrides_ambuigity(registry, decorator, caplog, assert_logs,
                                    insights):
    r1 = Resource(group='', version='v1', plural='pods', verbs=VERBS)
    r2 = Resource(group='metrics.k8s.io',
                  version='v1',
                  plural='pods',
                  verbs=VERBS)

    @decorator(plural='pods')
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1, r2])
    assert insights.watched_resources == {r1}
    assert_logs([], prohibited=[r"Ambiguous resources will not be served"])
Ejemplo n.º 6
0
def test_indexed_resources_are_duplicated_in_watched_resources(
        registry, decorator, insights):

    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=VERBS)

    @decorator('group1', 'version1', 'plural1')
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    assert insights.watched_resources
    assert insights.indexed_resources
    assert not insights.webhook_resources
Ejemplo n.º 7
0
def test_nonpatchable_excluded(registry, decorator, caplog, assert_logs,
                               insights):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=['watch', 'list'])

    @decorator('group1', 'version1', 'plural1')  # because it patches!
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    assert not insights.watched_resources
    assert_logs([
        r"Non-patchable resources will not be served: {plural1.version1.group1}"
    ])
Ejemplo n.º 8
0
def test_replacing_all_insights(registry):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=VERBS)
    r2 = Resource(group='group2',
                  version='version2',
                  plural='plural2',
                  verbs=VERBS)
    insights = Insights()
    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r2])
    assert insights.resources == {r2}
Ejemplo n.º 9
0
def test_nonwatchable_excluded(registry, decorator, caplog, assert_logs):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=[])

    @decorator('group1', 'version1', 'plural1')
    def fn(**_):
        ...

    insights = Insights()
    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1])
    assert not insights.resources
    assert_logs([
        r"Non-watchable resources will not be served: {plural1.version1.group1}"
    ])
Ejemplo n.º 10
0
def test_selectors_with_no_resources(registry, decorator, caplog, assert_logs,
                                     insights):
    r1 = Resource(group='group1',
                  version='version1',
                  plural='plural1',
                  verbs=VERBS)
    r2 = Resource(group='group2',
                  version='version2',
                  plural='plural2',
                  verbs=VERBS)

    @decorator(plural='plural3')
    def fn(**_):
        ...

    revise_resources(registry=registry,
                     insights=insights,
                     group=None,
                     resources=[r1, r2])
    assert not insights.watched_resources
    assert_logs([r"Unresolved resources cannot be served"])