From d977499ffeffc3e53311b8688321d47f5ed403c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 9 Aug 2023 15:51:10 +0200 Subject: [PATCH] rename cli tests to have a common suffix rename test_import_sops -> test_import_sops --- .../tests/{test_keys.py => age_keys.py} | 2 +- pkgs/clan-cli/tests/conftest.py | 2 +- .../{test_clan_admin.py => test_admin_cli.py} | 0 ...import_sops.py => test_import_sops_cli.py} | 12 +++---- .../{test_secrets.py => test_secrets_cli.py} | 36 +++++++++---------- .../{test_clan_ssh.py => test_ssh_cli.py} | 1 + 6 files changed, 27 insertions(+), 26 deletions(-) rename pkgs/clan-cli/tests/{test_keys.py => age_keys.py} (95%) rename pkgs/clan-cli/tests/{test_clan_admin.py => test_admin_cli.py} (100%) rename pkgs/clan-cli/tests/{test_import_sops.py => test_import_sops_cli.py} (78%) rename pkgs/clan-cli/tests/{test_secrets.py => test_secrets_cli.py} (78%) rename pkgs/clan-cli/tests/{test_clan_ssh.py => test_ssh_cli.py} (99%) diff --git a/pkgs/clan-cli/tests/test_keys.py b/pkgs/clan-cli/tests/age_keys.py similarity index 95% rename from pkgs/clan-cli/tests/test_keys.py rename to pkgs/clan-cli/tests/age_keys.py index 518a2be..5a0e038 100644 --- a/pkgs/clan-cli/tests/test_keys.py +++ b/pkgs/clan-cli/tests/age_keys.py @@ -24,7 +24,7 @@ KEYS = [ @pytest.fixture -def test_keys() -> list[KeyPair]: +def age_keys() -> list[KeyPair]: """ Root directory of the tests """ diff --git a/pkgs/clan-cli/tests/conftest.py b/pkgs/clan-cli/tests/conftest.py index 7bde26d..ec743b1 100644 --- a/pkgs/clan-cli/tests/conftest.py +++ b/pkgs/clan-cli/tests/conftest.py @@ -3,4 +3,4 @@ import sys sys.path.append(os.path.join(os.path.dirname(__file__), "helpers")) -pytest_plugins = ["temporary_dir", "clan_flake", "root", "test_keys"] +pytest_plugins = ["temporary_dir", "clan_flake", "root", "age_keys"] diff --git a/pkgs/clan-cli/tests/test_clan_admin.py b/pkgs/clan-cli/tests/test_admin_cli.py similarity index 100% rename from pkgs/clan-cli/tests/test_clan_admin.py rename to pkgs/clan-cli/tests/test_admin_cli.py diff --git a/pkgs/clan-cli/tests/test_import_sops.py b/pkgs/clan-cli/tests/test_import_sops_cli.py similarity index 78% rename from pkgs/clan-cli/tests/test_import_sops.py rename to pkgs/clan-cli/tests/test_import_sops_cli.py index b578dd0..73a6a13 100644 --- a/pkgs/clan-cli/tests/test_import_sops.py +++ b/pkgs/clan-cli/tests/test_import_sops_cli.py @@ -6,21 +6,21 @@ from environment import mock_env from secret_cli import SecretCli if TYPE_CHECKING: - from test_keys import KeyPair + from age_keys import KeyPair def test_import_sops( test_root: Path, clan_flake: Path, capsys: pytest.CaptureFixture, - test_keys: list["KeyPair"], + age_keys: list["KeyPair"], ) -> None: cli = SecretCli() - with mock_env(SOPS_AGE_KEY=test_keys[1].privkey): - cli.run(["machines", "add", "machine1", test_keys[0].pubkey]) - cli.run(["users", "add", "user1", test_keys[1].pubkey]) - cli.run(["users", "add", "user2", test_keys[2].pubkey]) + with mock_env(SOPS_AGE_KEY=age_keys[1].privkey): + cli.run(["machines", "add", "machine1", age_keys[0].pubkey]) + cli.run(["users", "add", "user1", age_keys[1].pubkey]) + cli.run(["users", "add", "user2", age_keys[2].pubkey]) cli.run(["groups", "add-user", "group1", "user1"]) cli.run(["groups", "add-user", "group1", "user2"]) diff --git a/pkgs/clan-cli/tests/test_secrets.py b/pkgs/clan-cli/tests/test_secrets_cli.py similarity index 78% rename from pkgs/clan-cli/tests/test_secrets.py rename to pkgs/clan-cli/tests/test_secrets_cli.py index 3b555f6..1d5ec3d 100644 --- a/pkgs/clan-cli/tests/test_secrets.py +++ b/pkgs/clan-cli/tests/test_secrets_cli.py @@ -9,22 +9,22 @@ from secret_cli import SecretCli from clan_cli.errors import ClanError if TYPE_CHECKING: - from test_keys import KeyPair + from age_keys import KeyPair def _test_identities( what: str, clan_flake: Path, capsys: pytest.CaptureFixture, - test_keys: list["KeyPair"], + age_keys: list["KeyPair"], ) -> None: cli = SecretCli() sops_folder = clan_flake / "sops" - cli.run([what, "add", "foo", test_keys[0].pubkey]) + cli.run([what, "add", "foo", age_keys[0].pubkey]) assert (sops_folder / what / "foo" / "key.json").exists() with pytest.raises(ClanError): - cli.run([what, "add", "foo", test_keys[0].pubkey]) + cli.run([what, "add", "foo", age_keys[0].pubkey]) cli.run( [ @@ -32,7 +32,7 @@ def _test_identities( "add", "-f", "foo", - test_keys[0].privkey, + age_keys[0].privkey, ] ) capsys.readouterr() # empty the buffer @@ -54,19 +54,19 @@ def _test_identities( def test_users( - clan_flake: Path, capsys: pytest.CaptureFixture, test_keys: list["KeyPair"] + clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"] ) -> None: - _test_identities("users", clan_flake, capsys, test_keys) + _test_identities("users", clan_flake, capsys, age_keys) def test_machines( - clan_flake: Path, capsys: pytest.CaptureFixture, test_keys: list["KeyPair"] + clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"] ) -> None: - _test_identities("machines", clan_flake, capsys, test_keys) + _test_identities("machines", clan_flake, capsys, age_keys) def test_groups( - clan_flake: Path, capsys: pytest.CaptureFixture, test_keys: list["KeyPair"] + clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"] ) -> None: cli = SecretCli() capsys.readouterr() # empty the buffer @@ -77,13 +77,13 @@ def test_groups( cli.run(["groups", "add-machine", "group1", "machine1"]) with pytest.raises(ClanError): # user does not exist yet cli.run(["groups", "add-user", "groupb1", "user1"]) - cli.run(["machines", "add", "machine1", test_keys[0].pubkey]) + cli.run(["machines", "add", "machine1", age_keys[0].pubkey]) cli.run(["groups", "add-machine", "group1", "machine1"]) # Should this fail? cli.run(["groups", "add-machine", "group1", "machine1"]) - cli.run(["users", "add", "user1", test_keys[0].pubkey]) + cli.run(["users", "add", "user1", age_keys[0].pubkey]) cli.run(["groups", "add-user", "group1", "user1"]) capsys.readouterr() # empty the buffer @@ -99,7 +99,7 @@ def test_groups( def test_secrets( - clan_flake: Path, capsys: pytest.CaptureFixture, test_keys: list["KeyPair"] + clan_flake: Path, capsys: pytest.CaptureFixture, age_keys: list["KeyPair"] ) -> None: cli = SecretCli() capsys.readouterr() # empty the buffer @@ -125,18 +125,18 @@ def test_secrets( cli.run(["list"]) assert capsys.readouterr().out == "key\n" - cli.run(["machines", "add", "machine1", test_keys[0].pubkey]) + cli.run(["machines", "add", "machine1", age_keys[0].pubkey]) cli.run(["machines", "add-secret", "machine1", "key"]) - with mock_env(SOPS_AGE_KEY=test_keys[0].privkey, SOPS_AGE_KEY_FILE=""): + with mock_env(SOPS_AGE_KEY=age_keys[0].privkey, SOPS_AGE_KEY_FILE=""): capsys.readouterr() cli.run(["get", "key"]) assert capsys.readouterr().out == "foo" cli.run(["machines", "remove-secret", "machine1", "key"]) - cli.run(["users", "add", "user1", test_keys[1].pubkey]) + cli.run(["users", "add", "user1", age_keys[1].pubkey]) cli.run(["users", "add-secret", "user1", "key"]) - with mock_env(SOPS_AGE_KEY=test_keys[1].privkey, SOPS_AGE_KEY_FILE=""): + with mock_env(SOPS_AGE_KEY=age_keys[1].privkey, SOPS_AGE_KEY_FILE=""): capsys.readouterr() cli.run(["get", "key"]) assert capsys.readouterr().out == "foo" @@ -151,7 +151,7 @@ def test_secrets( capsys.readouterr() # empty the buffer cli.run(["set", "--group", "admin-group", "key2"]) - with mock_env(SOPS_AGE_KEY=test_keys[1].privkey, SOPS_AGE_KEY_FILE=""): + with mock_env(SOPS_AGE_KEY=age_keys[1].privkey, SOPS_AGE_KEY_FILE=""): capsys.readouterr() cli.run(["get", "key"]) assert capsys.readouterr().out == "foo" diff --git a/pkgs/clan-cli/tests/test_clan_ssh.py b/pkgs/clan-cli/tests/test_ssh_cli.py similarity index 99% rename from pkgs/clan-cli/tests/test_clan_ssh.py rename to pkgs/clan-cli/tests/test_ssh_cli.py index 3c6a37c..8841571 100644 --- a/pkgs/clan-cli/tests/test_clan_ssh.py +++ b/pkgs/clan-cli/tests/test_ssh_cli.py @@ -6,6 +6,7 @@ import pytest_subprocess.fake_process from environment import mock_env from pytest_subprocess import utils +import clan_cli from clan_cli.ssh import cli