Ejemplo n.º 1
0
def test_register_context(fixtures_dir):
    input = fixtures_dir / 'generator_data' / 'register_context' / 'test.p10s'
    g = Generator()
    g.generate(input)

    s = fixtures_dir / 'generator_data' / 'register_context' / 'test.tf.json'
    s2 = fixtures_dir / 'generator_data' / 'register_context' / 'static_2.tf.json'
    da = fixtures_dir / 'generator_data' / 'register_context' / 'dynamic_a.tf.json'
    db = fixtures_dir / 'generator_data' / 'register_context' / 'dynamic_b.tf.json'
    dc = fixtures_dir / 'generator_data' / 'register_context' / 'dynamic_c.tf.json'

    assert s.exists()
    assert {'module': {'static': {'var': 's'}}} == json.load(s.open())

    assert s2.exists()
    assert {'module': {'static_2': {'var': 's2'}}} == json.load(s2.open())

    assert da.exists()
    assert {'module': {'dynamic_a': {}}} == json.load(da.open())

    assert db.exists()
    assert {'module': {'dynamic_b': {}}} == json.load(db.open())

    assert dc.exists()
    assert {'module': {'dynamic_c': {}}} == json.load(dc.open())
Ejemplo n.º 2
0
def test_find_p10s_files(fixtures_dir):
    base = fixtures_dir / 'generator_data' / 'find_p10s_files'
    top = base / 'top.p10s'
    bottom = base / 'sub1' / 'sub2' / 'bottom.p10s'

    expected = [top, bottom]
    actual = list(Generator()._p10s_scripts(base))
    assert expected == actual
Ejemplo n.º 3
0
def test_generate_with_lib2(fixtures_dir):
    input = fixtures_dir / 'generator_data' / 'with_lib' / 'sub' / 'bottom.p10s'
    g = Generator()
    g.generate(input)
    output = fixtures_dir / 'generator_data' / 'with_lib' / 'sub' / 'bottom.tf.json'
    assert output.exists()
    output_data = json.load(output.open())
    assert {'provider': {'whatever': {}}} == output_data
Ejemplo n.º 4
0
def test_pwd(fixtures_dir):
    input = fixtures_dir / 'generator_data' / 'simple' / 'pwd.p10s'
    g = Generator()
    g.generate(input)
    output = fixtures_dir / 'generator_data' / 'simple' / 'pwd.tf.json'
    assert output.exists()
    output_data = json.load(output.open())
    assert {
        'data': {
            'bar': {
                'foo': {
                    'pwd': str(input.parent.resolve())
                }
            }
        }
    } == output_data
Ejemplo n.º 5
0
def test_generate_k8s(fixtures_dir):
    input = fixtures_dir / 'generator_data' / 'simple' / 'single_k8s.p10s'
    g = Generator()
    g.generate(input)
    output = fixtures_dir / 'generator_data' / 'simple' / 'single_k8s.yaml'
    assert output.exists()
    output_data = output.open().read()
    assert """apiVersion: v1
data: {}
kind: ConfigMap
metadata:
  labels:
    env: prd
    grafana_dashboard: '1'
  name: foobar
""" == output_data
Ejemplo n.º 6
0
def test_generate(fixtures_dir):
    input = fixtures_dir / 'generator_data' / 'simple' / 'simple.p10s'
    g = Generator()
    g.generate(input)
    output = fixtures_dir / 'generator_data' / 'simple' / 'simple.tf.json'
    assert output.exists()
    output_data = json.load(output.open())
    assert {
        'resource': {
            'a': {
                'b': {
                    'count': 1
                },
                'c': {
                    'count': 2
                }
            },
            'b': {
                'b': {
                    'count': 3
                }
            }
        }
    } == output_data
Ejemplo n.º 7
0
def test_find_p10s_script_does_not_exist(fixtures_dir):
    with pytest.raises(FileNotFoundError):
        list(Generator()._p10s_scripts(fixtures_dir / 'does_not_exist.p10s'))