...

Text file src/github.com/emissary-ingress/emissary/v3/python/tests/unit/test_envvar_expansion.py

Documentation: github.com/emissary-ingress/emissary/v3/python/tests/unit

     1import logging
     2import os
     3import sys
     4
     5import pytest
     6
     7logging.basicConfig(
     8    level=logging.INFO,
     9    format="%(asctime)s test %(levelname)s: %(message)s",
    10    datefmt="%Y-%m-%d %H:%M:%S",
    11)
    12
    13logger = logging.getLogger("ambassador")
    14
    15from ambassador import Config
    16from ambassador.fetch import ResourceFetcher
    17
    18yaml = """
    19---
    20apiVersion: getambassador.io/v3alpha1
    21kind: Mapping
    22name: test_mapping
    23hostname: "*"
    24prefix: /test/
    25service: ${TEST_SERVICE}:9999
    26"""
    27
    28
    29def test_envvar_expansion():
    30    os.environ["TEST_SERVICE"] = "foo"
    31
    32    aconf = Config()
    33
    34    fetcher = ResourceFetcher(logger, aconf)
    35    fetcher.parse_yaml(yaml)
    36
    37    aconf.load_all(fetcher.sorted())
    38
    39    mappings = aconf.config["mappings"]
    40    test_mapping = mappings["test_mapping"]
    41
    42    assert test_mapping.service == "foo:9999"
    43
    44
    45if __name__ == "__main__":
    46    pytest.main(sys.argv)

View as plain text