Beispiel #1
0
def test_mapping_host_ok():
    test_yaml = """
---
apiVersion: x.getambassador.io/v3alpha1
kind: AmbassadorMapping
metadata:
  name: good-host-mapping
  namespace: default
spec:
  host: foo.example.com
  prefix: /wanted_group/
  service: star
"""

    r = compile_with_cachecheck(test_yaml, envoy_version="v3", errors_ok=True)

    ir = r["ir"]

    errors = ir.aconf.errors
    assert len(errors) == 0, "Expected no errors but got %s" % (json.dumps(
        errors, sort_keys=True, indent=4))

    found = 0

    for g in ir.groups.values():
        if g.prefix == "/wanted_group/":
            assert g.host == "foo.example.com"
            found += 1

    assert found == 1, "Expected 1 /wanted_group/ prefix, got %d" % found
Beispiel #2
0
def test_mapping_host_star_error():
    test_yaml = """
---
apiVersion: x.getambassador.io/v3alpha1
kind: AmbassadorMapping
metadata:
  name: bad-mapping
  namespace: default
spec:
  host: "*"
  prefix: /star/
  service: star
"""

    r = compile_with_cachecheck(test_yaml, envoy_version="v3", errors_ok=True)

    ir = r["ir"]

    # print(json.dumps(ir.aconf.errors, sort_keys=True, indent=4))

    errors = ir.aconf.errors["bad-mapping.default.1"]
    assert len(errors) == 1, f"Expected 1 error but got {len(errors)}"

    assert errors[0]["ok"] == False
    assert errors[0][
        "error"] == "host exact-match * contains *, which cannot match anything."

    for g in ir.groups.values():
        assert g.prefix != "/star/"