mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13: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,17 @@
|
||||
# eval_config.py tests
|
||||
|
||||
If you change something about the evaluation and need to update one of the
|
||||
result files here, you can run a command like this:
|
||||
|
||||
./disko2 dev eval example/simple-efi.nix > tests/disko_lib/eval_config/file-simple-efi-result.json
|
||||
|
||||
Change the paths depending on the example whose evaluation result changed.
|
||||
|
||||
If you're thinking "this sounds like snapshots to me" and "isn't there a pytest plugin for this?",
|
||||
then you'd be correct, but [pytest-insta](https://github.com/vberlier/pytest-insta) is not packaged
|
||||
in nixpkgs at the time of writing (2024-11-08).
|
||||
|
||||
If you're reading this, and you
|
||||
[search nixpkgs for "pytest-insta"](https://search.nixos.org/packages?channel=unstable&query=pytest-insta)
|
||||
AND this returns the `pytest-insta` package (or there is a new, better snapshotting plugin for pytest),
|
||||
please open an issue so we can replace this manual process with it!
|
||||
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"disk": {
|
||||
"main": {
|
||||
"content": {
|
||||
"device": "/dev/disk/by-id/some-disk-id",
|
||||
"efiGptPartitionFirst": true,
|
||||
"partitions": {
|
||||
"ESP": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"extraArgs": [],
|
||||
"format": "vfat",
|
||||
"mountOptions": [
|
||||
"umask=0077"
|
||||
],
|
||||
"mountpoint": "/boot",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem"
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"end": "+500M",
|
||||
"hybrid": null,
|
||||
"label": "disk-main-ESP",
|
||||
"name": "ESP",
|
||||
"priority": 1000,
|
||||
"size": "500M",
|
||||
"start": "0",
|
||||
"type": "EF00"
|
||||
},
|
||||
"root": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"extraArgs": [],
|
||||
"format": "ext4",
|
||||
"mountOptions": [
|
||||
"defaults"
|
||||
],
|
||||
"mountpoint": "/",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem"
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"end": "-0",
|
||||
"hybrid": null,
|
||||
"label": "disk-main-root",
|
||||
"name": "root",
|
||||
"priority": 9001,
|
||||
"size": "100%",
|
||||
"start": "0",
|
||||
"type": "8300"
|
||||
}
|
||||
},
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "gpt"
|
||||
},
|
||||
"device": "/dev/disk/by-id/some-disk-id",
|
||||
"imageName": "main",
|
||||
"imageSize": "2G",
|
||||
"name": "main",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "disk"
|
||||
}
|
||||
},
|
||||
"lvm_vg": {},
|
||||
"mdadm": {},
|
||||
"nodev": {},
|
||||
"zpool": {}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"disk": {
|
||||
"main": {
|
||||
"content": {
|
||||
"device": "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345",
|
||||
"efiGptPartitionFirst": true,
|
||||
"partitions": {
|
||||
"ESP": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"extraArgs": [],
|
||||
"format": "vfat",
|
||||
"mountOptions": [
|
||||
"umask=0077"
|
||||
],
|
||||
"mountpoint": "/boot",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem"
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"end": "+512M",
|
||||
"hybrid": null,
|
||||
"label": "disk-main-ESP",
|
||||
"name": "ESP",
|
||||
"priority": 1000,
|
||||
"size": "512M",
|
||||
"start": "0",
|
||||
"type": "EF00"
|
||||
},
|
||||
"boot": {
|
||||
"alignment": 0,
|
||||
"content": null,
|
||||
"device": "/dev/disk/by-partlabel/disk-main-boot",
|
||||
"end": "+1M",
|
||||
"hybrid": null,
|
||||
"label": "disk-main-boot",
|
||||
"name": "boot",
|
||||
"priority": 100,
|
||||
"size": "1M",
|
||||
"start": "0",
|
||||
"type": "EF02"
|
||||
},
|
||||
"root": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"extraArgs": [],
|
||||
"format": "ext4",
|
||||
"mountOptions": [
|
||||
"defaults"
|
||||
],
|
||||
"mountpoint": "/",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem"
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"end": "-0",
|
||||
"hybrid": null,
|
||||
"label": "disk-main-root",
|
||||
"name": "root",
|
||||
"priority": 9001,
|
||||
"size": "100%",
|
||||
"start": "0",
|
||||
"type": "8300"
|
||||
}
|
||||
},
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "gpt"
|
||||
},
|
||||
"device": "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345",
|
||||
"imageName": "main",
|
||||
"imageSize": "2G",
|
||||
"name": "main",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "disk"
|
||||
}
|
||||
},
|
||||
"lvm_vg": {},
|
||||
"mdadm": {},
|
||||
"nodev": {},
|
||||
"zpool": {}
|
||||
}
|
||||
@@ -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
|
||||
@@ -1,196 +0,0 @@
|
||||
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
|
||||
|
||||
|
||||
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_example_simple_efi() -> None:
|
||||
result = eval_config(disko_file="example/simple-efi.nix", flake=None)
|
||||
assert isinstance(result, DiskoSuccess)
|
||||
assert result.value == {
|
||||
"disk": {
|
||||
"main": {
|
||||
"content": {
|
||||
"device": "/dev/disk/by-id/some-disk-id",
|
||||
"efiGptPartitionFirst": True,
|
||||
"partitions": {
|
||||
"ESP": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"extraArgs": [],
|
||||
"format": "vfat",
|
||||
"mountOptions": ["umask=0077"],
|
||||
"mountpoint": "/boot",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem",
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"end": "+500M",
|
||||
"hybrid": None,
|
||||
"label": "disk-main-ESP",
|
||||
"name": "ESP",
|
||||
"priority": 1000,
|
||||
"size": "500M",
|
||||
"start": "0",
|
||||
"type": "EF00",
|
||||
},
|
||||
"root": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"extraArgs": [],
|
||||
"format": "ext4",
|
||||
"mountOptions": ["defaults"],
|
||||
"mountpoint": "/",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem",
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"end": "-0",
|
||||
"hybrid": None,
|
||||
"label": "disk-main-root",
|
||||
"name": "root",
|
||||
"priority": 9001,
|
||||
"size": "100%",
|
||||
"start": "0",
|
||||
"type": "8300",
|
||||
},
|
||||
},
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "gpt",
|
||||
},
|
||||
"device": "/dev/disk/by-id/some-disk-id",
|
||||
"imageName": "main",
|
||||
"imageSize": "2G",
|
||||
"name": "main",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "disk",
|
||||
}
|
||||
},
|
||||
"lvm_vg": {},
|
||||
"mdadm": {},
|
||||
"nodev": {},
|
||||
"zpool": {},
|
||||
}
|
||||
|
||||
|
||||
def test_eval_config_flake_testmachine() -> None:
|
||||
result = eval_config(disko_file=None, flake=".#testmachine")
|
||||
assert isinstance(result, DiskoSuccess)
|
||||
assert result.value == {
|
||||
"disk": {
|
||||
"main": {
|
||||
"content": {
|
||||
"device": "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345",
|
||||
"efiGptPartitionFirst": True,
|
||||
"partitions": {
|
||||
"ESP": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"extraArgs": [],
|
||||
"format": "vfat",
|
||||
"mountOptions": ["umask=0077"],
|
||||
"mountpoint": "/boot",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem",
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-ESP",
|
||||
"end": "+512M",
|
||||
"hybrid": None,
|
||||
"label": "disk-main-ESP",
|
||||
"name": "ESP",
|
||||
"priority": 1000,
|
||||
"size": "512M",
|
||||
"start": "0",
|
||||
"type": "EF00",
|
||||
},
|
||||
"boot": {
|
||||
"alignment": 0,
|
||||
"content": None,
|
||||
"device": "/dev/disk/by-partlabel/disk-main-boot",
|
||||
"end": "+1M",
|
||||
"hybrid": None,
|
||||
"label": "disk-main-boot",
|
||||
"name": "boot",
|
||||
"priority": 100,
|
||||
"size": "1M",
|
||||
"start": "0",
|
||||
"type": "EF02",
|
||||
},
|
||||
"root": {
|
||||
"alignment": 0,
|
||||
"content": {
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"extraArgs": [],
|
||||
"format": "ext4",
|
||||
"mountOptions": ["defaults"],
|
||||
"mountpoint": "/",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "filesystem",
|
||||
},
|
||||
"device": "/dev/disk/by-partlabel/disk-main-root",
|
||||
"end": "-0",
|
||||
"hybrid": None,
|
||||
"label": "disk-main-root",
|
||||
"name": "root",
|
||||
"priority": 9001,
|
||||
"size": "100%",
|
||||
"start": "0",
|
||||
"type": "8300",
|
||||
},
|
||||
},
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "gpt",
|
||||
},
|
||||
"device": "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_250GB_S21PNXAGB12345",
|
||||
"imageName": "main",
|
||||
"imageSize": "2G",
|
||||
"name": "main",
|
||||
"postCreateHook": "",
|
||||
"postMountHook": "",
|
||||
"preCreateHook": "",
|
||||
"preMountHook": "",
|
||||
"type": "disk",
|
||||
}
|
||||
},
|
||||
"lvm_vg": {},
|
||||
"mdadm": {},
|
||||
"nodev": {},
|
||||
"zpool": {},
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -10,7 +10,7 @@ CURRENT_DIR = Path(__file__).parent
|
||||
|
||||
|
||||
def test_generate_config_partial_failure_dos_table() -> None:
|
||||
with open(CURRENT_DIR / "lsblk-output.json") as f:
|
||||
with open(CURRENT_DIR / "partial_failure_dos_table-lsblk-output.json") as f:
|
||||
lsblk_result = device.list_block_devices(f.read())
|
||||
|
||||
assert isinstance(lsblk_result, DiskoSuccess)
|
||||
@@ -26,7 +26,7 @@ def test_generate_config_partial_failure_dos_table() -> None:
|
||||
}
|
||||
|
||||
assert result.messages[1].factory == warn_generate_partial_failure
|
||||
with open(CURRENT_DIR / "generate-result.json") as f:
|
||||
with open(CURRENT_DIR / "partial_failure_dos_table-generate-result.json") as f:
|
||||
assert result.messages[1].details["partial_config"] == json.load(f)
|
||||
assert result.messages[1].details["failed_devices"] == [PosixPath("/dev/sdc")]
|
||||
assert result.messages[1].details["successful_devices"] == [
|
||||
Reference in new issue
Block a user