|
| 1 | +import pytest |
| 2 | + |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +from conftest import RunnerFunc |
| 6 | + |
| 7 | +from commodore import version |
| 8 | + |
| 9 | + |
| 10 | +def test_version_cli(cli_runner: RunnerFunc): |
| 11 | + result = cli_runner(["version"]) |
| 12 | + assert result.output.startswith("Commodore ") |
| 13 | + # NOTE(sg): exit code is 0 if all external tools are available or 127 |
| 14 | + # otherwise. |
| 15 | + assert result.exit_code == 0 or result.exit_code == 127 |
| 16 | + |
| 17 | + |
| 18 | +def test_version_native_find_so_non_native(): |
| 19 | + with pytest.raises(ValueError) as exc: |
| 20 | + version._native_find_so("kapitan") |
| 21 | + assert "Unable to parse build info for kapitan: no unique *.so found" in str(exc) |
| 22 | + |
| 23 | + |
| 24 | +def test_version_reclass_rs_buildinfo_no_rust(): |
| 25 | + gojsonnet_so = version._native_find_so("gojsonnet") |
| 26 | + with patch.object(version, "_native_find_so") as native_find_so_mock: |
| 27 | + native_find_so_mock.return_value = gojsonnet_so |
| 28 | + rustc = version._reclass_rs_buildinfo() |
| 29 | + assert ( |
| 30 | + rustc |
| 31 | + == "Unable to parse build info for reclass-rs: " |
| 32 | + + "no unique rustc entry found in ELF .comment section" |
| 33 | + ) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.parametrize("dep", ["gojsonnet", "reclass-rs"]) |
| 37 | +def test_version_buildinfo_no_unique_so(dep: str): |
| 38 | + def mock_find_so(_dep): |
| 39 | + raise ValueError("Mock Error") |
| 40 | + |
| 41 | + with patch.object(version, "_native_find_so") as native_find_so_mock: |
| 42 | + native_find_so_mock.side_effect = mock_find_so |
| 43 | + build_info = version._buildinfo[dep]() |
| 44 | + assert build_info == "Mock Error" |
0 commit comments