Skip to content

Commit b8697b6

Browse files
fmoessbauerjan-kiszka
authored andcommitted
test: add test for failed fetching of repos
We currently only test the good case of fetching repos, however we also need to test the error path. We add a check for that as well by mocking the fetch_cmd implementation of a GitRepo. We further need to remove the commit, as otherwise the short-circuit implementation added in 021e961 skips the fetching. Signed-off-by: Felix Moessbauer <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent ea6ece9 commit b8697b6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_commands.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from kas import kas
3232
from kas.libkas import TaskExecError, KasUserError, run_cmd
3333
from kas.attestation import file_digest_slow
34+
from kas.repos import RepoFetchError
3435

3536

3637
@pytest.mark.dirsfromenv
@@ -82,6 +83,21 @@ def test_checkout(monkeykas, tmpdir):
8283
assert not (kas_bd / 'downloads').exists()
8384
assert not (kas_bd / 'sstate-cache').exists()
8485

86+
# test re-fetching (remove commit as nothing is fetched otherwise)
87+
with open('test.yml', 'r') as f:
88+
yml = yaml.safe_load(f)
89+
with open('test-no-commit.yml', 'w') as f:
90+
del yml['repos']['kas_1.1']['commit']
91+
yml['repos']['kas_1.1']['branch'] = 'master'
92+
yaml.safe_dump(yml, f)
93+
kas.kas(['checkout', '--update', 'test-no-commit.yml'])
94+
95+
with monkeykas.context() as mc:
96+
from kas.repos import GitRepo
97+
mc.setattr(GitRepo, "fetch_cmd", lambda _: ["false"])
98+
with pytest.raises(RepoFetchError):
99+
kas.kas(['checkout', '--update', 'test-no-commit.yml'])
100+
85101

86102
def test_invalid_checkout(monkeykas, tmpdir, capsys):
87103
tdir = str(tmpdir / 'test_commands')

0 commit comments

Comments
 (0)