def test_takeltest_unit_moleculeenv_no_gather_roles(moleculelog, tmp_path):
    my_playbook = """\
---
- name: converge
  hosts: all
  gather_facts: false
  roles:
    - my_role
"""
    med = tmp_path / 'molecule_ephemeral_directory'
    med.mkdir()

    msd = tmp_path / 'molecule_scenario_directory'
    msd.mkdir()

    (tmp_path / 'roles' / 'my_role').mkdir(parents=True)

    playbook_path = msd / 'playbook.yml'
    playbook_path.write_text(my_playbook)

    gather_roles = False
    testvars_roles_blocklist = []
    testvars_roles_exclusivelist = []
    testvars_roles_includelist = []
    testvars_roles_playbooks = []

    moleculeenv = MoleculeEnv(moleculelog, med, msd, gather_roles,
                              testvars_roles_blocklist,
                              testvars_roles_exclusivelist,
                              testvars_roles_includelist,
                              testvars_roles_playbooks)

    assert moleculeenv.get_roles() == []
def test_takeltest_unit_moleculeenv_get_roles_fallback_project(
        moleculelog, tmp_path):
    my_roles = ['my_role_1']

    med = tmp_path / 'molecule_ephemeral_directory'
    med.mkdir()

    msd = tmp_path / 'molecule/molecule_scenario_directory'
    msd.mkdir(parents=True)

    my_role_1 = tmp_path / 'roles' / 'my_role_1'
    my_role_1.mkdir(parents=True)

    gather_roles = True
    testvars_roles_blocklist = []
    testvars_roles_exclusivelist = []
    testvars_roles_includelist = []
    testvars_roles_playbooks = []

    moleculeenv = MoleculeEnv(moleculelog, med, msd, gather_roles,
                              testvars_roles_blocklist,
                              testvars_roles_exclusivelist,
                              testvars_roles_includelist,
                              testvars_roles_playbooks)

    assert moleculeenv.get_roles() == my_roles
def test_takeltest_unit_moleculeenv_get_roles_playbooks(moleculelog, tmp_path):
    my_playbook_1 = """\
---
- name: converge
  hosts: all
  gather_facts: false
  roles:
    - my_role_1
"""
    my_playbook_2 = """\
---
- name: converge
  hosts: all
  gather_facts: false
  roles:
    - my_role_2
"""
    my_roles = ['my_role_1', 'my_role_2']

    med = tmp_path / 'molecule_ephemeral_directory'
    med.mkdir()

    msd = tmp_path / 'molecule_scenario_directory'
    msd.mkdir()

    my_role_1 = tmp_path / 'roles' / 'my_role_1'
    my_role_1.mkdir(parents=True)

    my_role_2 = tmp_path / 'roles' / 'my_role_2'
    my_role_2.mkdir(parents=True)

    playbook_path = tmp_path / 'custom1.yml'
    playbook_path.write_text(my_playbook_1)

    playbook_path = tmp_path / 'custom2.yml'
    playbook_path.write_text(my_playbook_2)

    gather_roles = True
    testvars_roles_blocklist = []
    testvars_roles_exclusivelist = []
    testvars_roles_includelist = []
    testvars_roles_playbooks = ['../custom1.yml', '../custom2.yml']

    moleculeenv = MoleculeEnv(moleculelog, med, msd, gather_roles,
                              testvars_roles_blocklist,
                              testvars_roles_exclusivelist,
                              testvars_roles_includelist,
                              testvars_roles_playbooks)

    assert moleculeenv.get_roles() == my_roles
def test_takeltest_unit_moleculeenv_roles_from_playboook_expand_path(
        moleculelog, monkeypatch, tmp_path):
    monkeypatch.setenv('TAKELAGE_MOLECULE_CONVERGE_PLAYBOOK',
                       'my_playbook.yml')

    my_molecule_yml = """\
---
provisioner:
    name: ansible
    playbooks:
        converge: >-
          ${TAKELAGE_MOLECULE_CONVERGE_PLAYBOOK:-custom-playbook.yml}
"""
    my_playbook = """\
---
- name: converge
  hosts: all
  gather_facts: false
  roles:
    - my_role
"""
    med = tmp_path / 'molecule_ephemeral_directory'
    med.mkdir()

    msd = tmp_path / 'molecule_scenario_directory'
    msd.mkdir()

    (tmp_path / 'roles' / 'my_role').mkdir(parents=True)

    molecule_yml_path = msd / 'molecule.yml'
    molecule_yml_path.write_text(my_molecule_yml)

    playbook_path = msd / 'my_playbook.yml'
    playbook_path.write_text(my_playbook)

    gather_roles = True
    testvars_roles_blocklist = []
    testvars_roles_exclusivelist = []
    testvars_roles_includelist = []
    testvars_roles_playbooks = []

    moleculeenv = MoleculeEnv(moleculelog, med, msd, gather_roles,
                              testvars_roles_blocklist,
                              testvars_roles_exclusivelist,
                              testvars_roles_includelist,
                              testvars_roles_playbooks)

    assert moleculeenv.get_roles() == ['my_role']