Ejemplo n.º 1
0
def test_with_scenarios(mocker, folder):
    ansible = Ansible(base=folder)
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    ansible.options.molecule_config_files = []
    # ansible._scenarios = scenarios  # pylint: disable=protected-access
    assert ansible.directory == os.path.realpath(folder)
Ejemplo n.º 2
0
def test_with_scenarios(mocker, folder, expected):
    ansible = Ansible(base=folder)
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    # ansible._scenarios = scenarios  # pylint: disable=protected-access
    assert ansible.directory == os.path.realpath(folder)
    assert ansible.is_ansible == expected
Ejemplo n.º 3
0
def test_scenarios_with_base_molecule_config(mocker):
    ansible = Ansible("tests/fixtures/collection")
    base_configs = [os.path.join(ansible.directory, "molecule.yml")]
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    ansible.options.molecule_config_files = base_configs
    assert ansible.molecule_config_files() == base_configs
Ejemplo n.º 4
0
def test_scenarios_correct(mocker):
    ansible = Ansible("tests/fixtures/collection")
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    ansible.options.molecule_config_files = []
    assert len(ansible.scenarios) == 6
    # Second call to be sure we are not walking twice
    assert len(ansible.scenarios) == 6
Ejemplo n.º 5
0
 def test_collection_when_collection(self, c_mock, r_mock, tc_mock):
     c_mock.return_value = True
     r_mock.return_value = False
     tcs = ["a", "b"]
     tc_mock.return_value = tcs
     ansible = Ansible()
     self.assertTrue(ansible.is_ansible())
     self.assertEqual(ansible.get_tox_cases()[:-1], tcs)
Ejemplo n.º 6
0
def test_scenarios_with_global_molecule_config(mocker):
    ansible = Ansible("tests/fixtures/not_collection")
    global_config = [
        os.path.join(ansible.directory, ".config/molecule/config.yml")
    ]
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    ansible.options.molecule_config_files = []
    assert ansible.molecule_config_files() == global_config
Ejemplo n.º 7
0
def test_ignore_paths(mocker):
    ansible = Ansible("tests/fixtures/collection")
    ansible.options = mocker.Mock()
    # We're ignoring one of them
    ansible.options.ignore_paths = ["one"]
    ansible.options.molecule_config_files = [
        "tests/fixtures/collection/molecule.yml"
    ]
    assert len(ansible.scenarios) == 5
    assert len(ansible.molecule_config) == 1
Ejemplo n.º 8
0
    def tox_configure(config):
        """If the current folder includes a file named `galaxy.yml`, then look for
        a roles directory and generate environments for every (role, scenario)
        combo that is discovered therein."""
        tox = tox_helper.Tox(config)
        options = Options(tox)
        ansible = Ansible(options=options, base=tox.toxinidir)

        # Only execute inside of a collection, otherwise we have nothing to do
        if not ansible.is_ansible:
            return

        # Create any test cases that are discovered in the directory structure and
        # expand them per any configured matrix axes in the config file
        tox_cases = ansible.tox_cases
        tox_cases = options.expand_matrix(tox_cases)

        # Add them to the envconfig list before testing for explicit calls, because
        # we want the user to be able to specifically state an auto-generated
        # test, if they want to
        tox.add_envconfigs(tox_cases, options)

        # Don't filter down or add to envlist if an environment has been
        # specified by the user
        if hasattr(config, "envlist_explicit") and config.envlist_explicit:
            return

        # Add the items we generated to the envlist to be executed by default
        # Set, because there might be dupes
        config.envlist = list(set(config.envlist + config.ansible_envlist))

        # Since the user hasn't been explicit about which environments to execute
        # against, then we add the ones we've generated to the list, and then we
        # filter it
        if options.do_filter():
            envfilter = Filter(options)
            # Actually modify the envconfigs, because we don't care about ones we
            # won't be executing
            config.envconfigs = envfilter.filter(config.envconfigs)
            config.envlist = list(config.envconfigs.keys())
        config.envlist.sort()
        config.envlist_default = config.envlist
        if len(config.envlist) == 0:
            print("****** No environments matched. This is a problem.")
            sys.exit(101)
Ejemplo n.º 9
0
def test_scenarios_correct(mocker):
    ansible = Ansible("tests/fixtures/collection")
    ansible.options = mocker.Mock()
    ansible.options.ignore_paths = []
    assert len(ansible.scenarios) == 6
Ejemplo n.º 10
0
def test_with_full_path():
    ansible = Ansible("/dev")
    assert ansible.directory == "/dev"
Ejemplo n.º 11
0
 def test_collection_when_is_collection(self, c_mock, r_mock):
     c_mock.return_value = False
     r_mock.return_value = False
     ansible = Ansible()
     self.assertFalse(ansible.is_ansible())
     self.assertEqual(len(ansible.get_tox_cases()), 1)