mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
tests: Put tests with snapshots into directories
This makes the tests more readable and easier to browse. Making sure the tests always run fine, no matter from which directory they're started is a little detail we should either test for or document.
This commit is contained in:
1 parent
6b360a2534
commit
c5d1a42af7
8 files changed
+237
-198
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from disko_lib.eval_config import eval_config
|
||||
from disko_lib.messages.msgs import err_missing_arguments, err_too_many_arguments
|
||||
from disko_lib.result import DiskoError, DiskoSuccess
|
||||
|
||||
CURRENT_DIR = Path(__file__).parent
|
||||
ROOT_DIR = CURRENT_DIR.parent.parent.parent
|
||||
assert (ROOT_DIR / "flake.nix").exists()
|
||||
|
||||
|
||||
def test_eval_config_missing_arguments() -> None:
|
||||
result = eval_config(disko_file=None, flake=None)
|
||||
assert isinstance(result, DiskoError)
|
||||
assert result.messages[0].factory == err_missing_arguments
|
||||
assert result.context == "validate args"
|
||||
|
||||
|
||||
def test_eval_config_too_many_arguments() -> None:
|
||||
result = eval_config(disko_file="foo", flake="bar")
|
||||
assert isinstance(result, DiskoError)
|
||||
assert result.messages[0].factory == err_too_many_arguments
|
||||
assert result.context == "validate args"
|
||||
|
||||
|
||||
def test_eval_config_disk_file() -> None:
|
||||
disko_file_path = ROOT_DIR / "example" / "simple-efi.nix"
|
||||
result = eval_config(disko_file=str(disko_file_path), flake=None)
|
||||
assert isinstance(result, DiskoSuccess)
|
||||
with open(CURRENT_DIR / "file-simple-efi-result.json") as f:
|
||||
expected_result = json.load(f)
|
||||
assert result.value == expected_result
|
||||
|
||||
|
||||
def test_eval_config_flake_testmachine() -> None:
|
||||
result = eval_config(disko_file=None, flake=f"{ROOT_DIR}#testmachine")
|
||||
assert isinstance(result, DiskoSuccess)
|
||||
with open(CURRENT_DIR / "flake-testmachine-result.json") as f:
|
||||
expected_result = json.load(f)
|
||||
assert result.value == expected_result
|
||||
Reference in new issue
Block a user