fix(clan_app/test): fixup after rebase

This commit is contained in:
Johannes Kirschbauer
2025-04-08 20:43:01 +02:00
parent e9ce7376f2
commit 0ced167912
6 changed files with 26 additions and 31 deletions

View File

@@ -118,7 +118,7 @@ pythonRuntime.pkgs.buildPythonApplication {
echo "STARTING ..." echo "STARTING ..."
export WEBVIEW_LIB_DIR="${webview-lib}/lib" export WEBVIEW_LIB_DIR="${webview-lib}/lib"
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
python -m pytest -s -m "not impure" ./clan_cli/tests python -m pytest -s -m "not impure" ./tests
touch $out touch $out
''; '';
}; };

View File

@@ -13,11 +13,10 @@ import pytest
from clan_cli.dirs import TemplateType, clan_templates, nixpkgs_source from clan_cli.dirs import TemplateType, clan_templates, nixpkgs_source
from clan_cli.locked_open import locked_open from clan_cli.locked_open import locked_open
from clan_cli.nix import nix_test_store from clan_cli.nix import nix_test_store
from clan_cli.tests import age_keys from clan_cli.tests import age_keys
from clan_cli.tests.temporary_dir import TEMPDIR
from clan_cli.tests.fixture_error import FixtureError from clan_cli.tests.fixture_error import FixtureError
from clan_cli.tests.root import CLAN_CORE from clan_cli.tests.root import CLAN_CORE
from clan_cli.tests.temporary_dir import TEMPDIR
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@@ -5,7 +5,6 @@ from pathlib import Path
import pytest import pytest
from clan_cli.cmd import run from clan_cli.cmd import run
from clan_cli.nix import nix_flake_show from clan_cli.nix import nix_flake_show
from clan_cli.tests.fixtures_flakes import FlakeForTest, substitute from clan_cli.tests.fixtures_flakes import FlakeForTest, substitute
from clan_cli.tests.helpers import cli from clan_cli.tests.helpers import cli
from clan_cli.tests.stdout import CaptureOutput from clan_cli.tests.stdout import CaptureOutput

View File

@@ -1,9 +1,8 @@
import pytest import pytest
from age_keys import SopsSetup, assert_secrets_file_recipients
from clan_cli.inventory import load_inventory_json from clan_cli.inventory import load_inventory_json
from clan_cli.secrets.folders import sops_machines_folder from clan_cli.secrets.folders import sops_machines_folder
from clan_cli.tests import fixtures_flakes from clan_cli.tests import fixtures_flakes
from clan_cli.tests.age_keys import SopsSetup, assert_secrets_file_recipients
from clan_cli.tests.helpers import cli from clan_cli.tests.helpers import cli
from clan_cli.tests.stdout import CaptureOutput from clan_cli.tests.stdout import CaptureOutput
@@ -90,9 +89,9 @@ def test_machine_delete(
cli.run(set_shared_secret) cli.run(set_shared_secret)
my_machine_sops_folder = sops_machines_folder(flake.path) / "my-machine" my_machine_sops_folder = sops_machines_folder(flake.path) / "my-machine"
assert ( assert my_machine_sops_folder.is_dir(), (
my_machine_sops_folder.is_dir() "A sops folder for `my-machine` should have been created with its public key"
), "A sops folder for `my-machine` should have been created with its public key" )
# define some vars generator for `my-machine`: # define some vars generator for `my-machine`:
config = flake.machines["my-machine"] config = flake.machines["my-machine"]
@@ -110,16 +109,16 @@ def test_machine_delete(
cli.run(["vars", "generate", "--flake", str(flake.path), "my-machine"]) cli.run(["vars", "generate", "--flake", str(flake.path), "my-machine"])
my_machine_vars_store = flake.path / "vars/per-machine" / "my-machine" my_machine_vars_store = flake.path / "vars/per-machine" / "my-machine"
assert ( assert my_machine_vars_store.is_dir(), (
my_machine_vars_store.is_dir() "A vars directory should have been created for `my-machine`"
), "A vars directory should have been created for `my-machine`" )
cli.run(["machines", "delete", "--flake", str(flake.path), "my-machine"]) cli.run(["machines", "delete", "--flake", str(flake.path), "my-machine"])
assert ( assert not my_machine_vars_store.exists(), (
not my_machine_vars_store.exists() "The vars directory for `my-machine` should have been deleted"
), "The vars directory for `my-machine` should have been deleted" )
assert ( assert not my_machine_sops_folder.exists(), (
not my_machine_sops_folder.exists() "The sops folder holding the public key for `my-machine` should have been deleted"
), "The sops folder holding the public key for `my-machine` should have been deleted" )
expected_recipients = [admin_key, machine2_key] expected_recipients = [admin_key, machine2_key]
assert_secrets_file_recipients(flake.path, shared_secret_name, expected_recipients) assert_secrets_file_recipients(flake.path, shared_secret_name, expected_recipients)

View File

@@ -7,12 +7,10 @@ from contextlib import contextmanager
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
from age_keys import assert_secrets_file_recipients
from clan_cli.errors import ClanError from clan_cli.errors import ClanError
from clan_cli.tests.age_keys import assert_secrets_file_recipients
from gpg_keys import GpgKey
from clan_cli.secrets.folders import sops_secrets_folder
from clan_cli.tests.fixtures_flakes import FlakeForTest from clan_cli.tests.fixtures_flakes import FlakeForTest
from clan_cli.tests.gpg_keys import GpgKey
from clan_cli.tests.helpers import cli from clan_cli.tests.helpers import cli
from clan_cli.tests.stdout import CaptureOutput from clan_cli.tests.stdout import CaptureOutput

View File

@@ -326,9 +326,9 @@ def test_generated_shared_secret_sops(
shared_generator["script"] = "echo hello > $out/my_shared_secret" shared_generator["script"] = "echo hello > $out/my_shared_secret"
m2_config = flake.machines["machine2"] m2_config = flake.machines["machine2"]
m2_config["nixpkgs"]["hostPlatform"] = "x86_64-linux" m2_config["nixpkgs"]["hostPlatform"] = "x86_64-linux"
m2_config["clan"]["core"]["vars"]["generators"][ m2_config["clan"]["core"]["vars"]["generators"]["my_shared_generator"] = (
"my_shared_generator" shared_generator.copy()
] = shared_generator.copy() )
flake.refresh() flake.refresh()
monkeypatch.chdir(flake.path) monkeypatch.chdir(flake.path)
machine1 = Machine(name="machine1", flake=Flake(str(flake.path))) machine1 = Machine(name="machine1", flake=Flake(str(flake.path)))
@@ -769,9 +769,9 @@ def test_migration(
my_service = config["clan"]["core"]["facts"]["services"]["my_service"] my_service = config["clan"]["core"]["facts"]["services"]["my_service"]
my_service["public"]["my_value"] = {} my_service["public"]["my_value"] = {}
my_service["secret"]["my_secret"] = {} my_service["secret"]["my_secret"] = {}
my_service["generator"][ my_service["generator"]["script"] = (
"script" "echo -n hello > $facts/my_value && echo -n hello > $secrets/my_secret"
] = "echo -n hello > $facts/my_value && echo -n hello > $secrets/my_secret" )
my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"] my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"]
my_generator["files"]["my_value"]["secret"] = False my_generator["files"]["my_value"]["secret"] = False
my_generator["files"]["my_secret"]["secret"] = True my_generator["files"]["my_secret"]["secret"] = True
@@ -840,9 +840,9 @@ def test_fails_when_files_are_left_from_other_backend(
regenerate=False, regenerate=False,
) )
# Will raise. It was secret before, but now it's not. # Will raise. It was secret before, but now it's not.
my_secret_generator["files"]["my_secret"][ my_secret_generator["files"]["my_secret"]["secret"] = (
"secret" False # secret -> public (NOT OK)
] = False # secret -> public (NOT OK) )
# WIll not raise. It was not secret before, and it's secret now. # WIll not raise. It was not secret before, and it's secret now.
my_value_generator["files"]["my_value"]["secret"] = True # public -> secret (OK) my_value_generator["files"]["my_value"]["secret"] = True # public -> secret (OK)
flake.refresh() flake.refresh()