|
| 1 | +""" |
| 2 | +Conftest for changing targetRef field in policies |
| 3 | +""" |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from testsuite.gateway import GatewayRoute, GatewayListener, Hostname, Exposer |
| 8 | +from testsuite.gateway.gateway_api.gateway import KuadrantGateway |
| 9 | +from testsuite.gateway.gateway_api.hostname import DNSPolicyExposer |
| 10 | +from testsuite.gateway.gateway_api.route import HTTPRoute |
| 11 | +from testsuite.kuadrant.policy.dns import DNSPolicy |
| 12 | + |
| 13 | +pytestmark = [pytest.mark.kuadrant_only, pytest.mark.dnspolicy] |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture(scope="module") |
| 17 | +def exposer2(request, cluster) -> Exposer: |
| 18 | + """Second DNSPolicyExposer setup for Gateway B""" |
| 19 | + exposer = DNSPolicyExposer(cluster) |
| 20 | + request.addfinalizer(exposer.delete) |
| 21 | + exposer.commit() |
| 22 | + return exposer |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture(scope="module") |
| 26 | +def base_domain2(exposer2): |
| 27 | + """Returns preconfigured base domain for the second Gateway""" |
| 28 | + return exposer2.base_domain |
| 29 | + |
| 30 | + |
| 31 | +@pytest.fixture(scope="module") |
| 32 | +def wildcard_domain2(base_domain2): |
| 33 | + """Wildcard domain for Gateway B""" |
| 34 | + return f"*.{base_domain2}" |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture(scope="module") |
| 38 | +def gateway(request, cluster, blame, wildcard_domain, module_label): |
| 39 | + """Create and configure Gateway A""" |
| 40 | + gw = KuadrantGateway.create_instance(cluster, blame("gw"), {"app": module_label}) |
| 41 | + gw.add_listener(GatewayListener(hostname=wildcard_domain)) |
| 42 | + request.addfinalizer(gw.delete) |
| 43 | + gw.commit() |
| 44 | + gw.wait_for_ready() |
| 45 | + return gw |
| 46 | + |
| 47 | + |
| 48 | +@pytest.fixture(scope="module") |
| 49 | +def gateway2(request, cluster, blame, wildcard_domain2, module_label): |
| 50 | + """Create and configure Gateway B""" |
| 51 | + gw = KuadrantGateway.create_instance(cluster, blame("gw2"), {"app": module_label}) |
| 52 | + gw.add_listener(GatewayListener(hostname=wildcard_domain2)) |
| 53 | + request.addfinalizer(gw.delete) |
| 54 | + gw.commit() |
| 55 | + gw.wait_for_ready() |
| 56 | + return gw |
| 57 | + |
| 58 | + |
| 59 | +@pytest.fixture(scope="module") |
| 60 | +def hostname2(gateway2, exposer2, blame) -> Hostname: |
| 61 | + """Expose Hostname for Gateway B""" |
| 62 | + hostname = exposer2.expose_hostname(blame("hostname2"), gateway2) |
| 63 | + return hostname |
| 64 | + |
| 65 | + |
| 66 | +@pytest.fixture(scope="module") |
| 67 | +def route2(request, gateway2, blame, hostname2, module_label, backend) -> GatewayRoute: |
| 68 | + """Create and configure Route B""" |
| 69 | + route = HTTPRoute.create_instance(gateway2.cluster, blame("route2"), gateway2, {"app": module_label}) |
| 70 | + route.add_hostname(hostname2.hostname) |
| 71 | + route.add_backend(backend) |
| 72 | + request.addfinalizer(route.delete) |
| 73 | + route.commit() |
| 74 | + route.wait_for_ready() |
| 75 | + return route |
| 76 | + |
| 77 | + |
| 78 | +@pytest.fixture(scope="module") |
| 79 | +def client2(route2, hostname2): # pylint: disable=unused-argument |
| 80 | + """Returns httpx client for Gateway B""" |
| 81 | + client = hostname2.client() |
| 82 | + yield client |
| 83 | + client.close() |
| 84 | + |
| 85 | + |
| 86 | +@pytest.fixture(scope="module") |
| 87 | +def dns_policy2(blame, gateway2, module_label, dns_provider_secret, request): |
| 88 | + """DNSPolicy fixture for Gateway B""" |
| 89 | + policy = DNSPolicy.create_instance( |
| 90 | + gateway2.cluster, blame("dns2"), gateway2, dns_provider_secret, labels={"app": module_label} |
| 91 | + ) |
| 92 | + request.addfinalizer(policy.delete) |
| 93 | + policy.commit() |
| 94 | + policy.wait_for_ready() |
| 95 | + return policy |
0 commit comments