Skip to content

Commit 2acb6f0

Browse files
committed
Add tests for commodore version
1 parent ed86321 commit 2acb6f0

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ def test_package_update_command():
102102
def test_package_sync_command():
103103
exit_status = call("commodore package sync --help", shell=True)
104104
assert exit_status == 0
105+
106+
107+
def test_version_command():
108+
exit_status = call("commodore version --help", shell=True)
109+
assert exit_status == 0

tests/test_version.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)