Skip to content

Commit

Permalink
Test custom driver name feature
Browse files Browse the repository at this point in the history
Test if `molecule-`, `molecule_`, `custom-`, `custom_` are
valid prefixes as driver name.

Test that any other name fails the validation.

Signed-off-by: Gloria Ciavarrini <[email protected]>
  • Loading branch information
gciavarrini committed Jan 10, 2023
1 parent 2f3929e commit 83fb15e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/molecule/test/unit/model/v2/test_driver_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _model_driver_errors_section_data():
}
}


@pytest.fixture
def _model_driver_errors_section_data_no_prefix():
return {
Expand All @@ -57,25 +58,27 @@ def _model_driver_errors_section_data_no_prefix():
}
}


@pytest.mark.parametrize(
"_config",
[
"_model_driver_errors_section_data",
"_model_driver_errors_section_data_no_prefix"
"_model_driver_errors_section_data_no_prefix",
],
indirect=True
indirect=True,
)
def test_driver_has_errors(_config):
base_error_msg = "is not one of ['azure', 'ec2', 'delegated', 'docker', 'containers', 'openstack', 'podman', 'vagrant', 'digitalocean', 'gce', 'libvirt', 'lxd', 'molecule_*', 'custom_*']"
base_error_msg = "is not one of ['azure', 'ec2', 'delegated', 'docker', 'containers', 'openstack', 'podman', 'vagrant', 'digitalocean', 'gce', 'libvirt', 'lxd', 'molecule-*', 'molecule_*', 'custom-*', 'custom_*']"

driver_name = str(_config["driver"]["name"])
if(type(_config["driver"]["name"]) is str):
if type(_config["driver"]["name"]) is str:
# add single quotes for string
driver_name = f"'{driver_name}'"

error_msg = [' '.join((driver_name, base_error_msg))]
error_msg = [" ".join((driver_name, base_error_msg))]
assert error_msg == schema_v3.validate(_config)


@pytest.fixture
def _model_driver_provider_name_nullable_section_data():
return {"driver": {"provider": {"name": None}}}
Expand All @@ -93,11 +96,35 @@ def _model_driver_allows_delegated_section_data():
return {"driver": {"name": "delegated"}}


@pytest.fixture
def _model_driver_allows_molecule_section_data1():
return {"driver": {"name": "molecule-test_driver.name"}}


@pytest.fixture
def _model_driver_allows_molecule_section_data2():
return {"driver": {"name": "molecule_test_driver.name"}}


@pytest.fixture
def _model_driver_allows_custom_section_data1():
return {"driver": {"name": "custom-test_driver.name"}}


@pytest.fixture
def _model_driver_allows_custom_section_data2():
return {"driver": {"name": "custom_test_driver.name"}}


###
@pytest.mark.parametrize(
"_config",
[
("_model_driver_allows_delegated_section_data"),
("_model_driver_allows_molecule_section_data1"),
("_model_driver_allows_molecule_section_data2"),
("_model_driver_allows_custom_section_data2"),
("_model_driver_allows_custom_section_data1"),
],
indirect=True,
)
Expand Down

0 comments on commit 83fb15e

Please sign in to comment.