diff --git a/dbt_meshify/utilities/versioner.py b/dbt_meshify/utilities/versioner.py index f1b7531..86d74d4 100644 --- a/dbt_meshify/utilities/versioner.py +++ b/dbt_meshify/utilities/versioner.py @@ -165,7 +165,7 @@ def bump_version( next_version_file_name = model_path.parent / Path( f"{defined_in}.{model.language}" if defined_in - else f"{model.name}_v{new_latest_version_number}.{model.language}" + else f"{model.name}_v{new_greatest_version_number}.{model.language}" ) change_set = ChangeSet() diff --git a/tests/integration/test_version_command.py b/tests/integration/test_version_command.py index e9ecb68..b9ed315 100644 --- a/tests/integration/test_version_command.py +++ b/tests/integration/test_version_command.py @@ -1,3 +1,4 @@ +import shutil from pathlib import Path import pytest @@ -281,6 +282,61 @@ def test_bump_version_in_yml( assert actual == yaml.safe_load(end_yml) +@pytest.mark.parametrize( + "start_yml,end_yml,expected_files,command_options", + [ + ( + model_yml_increment_version, + expected_versioned_model_yml_increment_version_with_prerelease, + ["shared_model_v1.sql", "shared_model_v2.sql"], + ["--prerelease"], + ) + ], +) +def test_bump_version_prerelease_in_yml( + start_yml, end_yml, expected_files, command_options, project +): + # Create the original versioned model + shutil.move( + Path(proj_path / "models" / "shared_model.sql"), + Path(proj_path / "models" / "shared_model_v1.sql"), + ) + yml_file = proj_path / "models" / "_models.yml" + yml_file.parent.mkdir(parents=True, exist_ok=True) + runner = CliRunner() + # only create file if start_yml is not None + # in situations where models don't have a patch path, there isn't a yml file to read from + if start_yml: + yml_file.touch() + start_yml_content = yaml.safe_load(start_yml) + with open(yml_file, "w+") as f: + yaml.safe_dump(start_yml_content, f, sort_keys=False) + base_command = [ + "operation", + "bump-version", + "--select", + "shared_model", + "--project-path", + str(proj_path), + ] + base_command.extend(command_options) + result = runner.invoke(cli, base_command) + print(result.stdout) + assert result.exit_code == 0 + # reset the read path to the default in the logic + with open(yml_file, "r") as f: + actual = yaml.safe_load(f) + + for file in expected_files: + path = proj_path / "models" / file + try: + assert path.is_file() + except Exception: + logger.exception(f"File {file} not found") + + assert actual == yaml.safe_load(end_yml) + + @pytest.mark.parametrize( "start_yml,start_files", [