test(services): run tests during system builds

This commit is contained in:
2026-09-19 21:05:41 -04:00
parent e2c240ba4b
commit ac4746277d
4 changed files with 69 additions and 35 deletions
-19
View File
@@ -1,19 +0,0 @@
name: pytest
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
pytest:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Run tests
run: nix develop .#devShells.x86_64-linux.default -c pytest tests
+35 -5
View File
@@ -1,4 +1,5 @@
{ {
inputs,
pkgs, pkgs,
lib, lib,
config, config,
@@ -6,6 +7,11 @@
}: }:
let let
cfg = config.services.snapshot_manager; cfg = config.services.snapshot_manager;
snapshotManagerPackages =
ps: with ps; [
apprise
typer
];
in in
{ {
options = { options = {
@@ -36,15 +42,39 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
nixpkgs.overlays = [ nixpkgs.overlays = [
(final: _prev: { (final: _prev: {
snapshot_manager_python = final.python314.withPackages ( snapshot_manager_python = final.python314.withPackages snapshotManagerPackages;
ps: with ps; [ snapshot_manager_test_python = final.python314.withPackages (
apprise ps:
typer snapshotManagerPackages ps
] ++ (with ps; [
pyfakefs
pytest
pytest-asyncio
pytest-mock
pytest-xdist
])
); );
snapshot_manager_tests =
final.runCommand "snapshot-manager-tests"
{
nativeBuildInputs = [ final.snapshot_manager_test_python ];
}
''
export HOME="$TMPDIR"
cd ${inputs.self}
pytest \
-o cache_dir="$TMPDIR/pytest-cache" \
tests/test_common.py \
tests/test_signal_alert.py \
tests/test_snapshot_manager.py \
tests/test_zfs.py
touch "$out"
'';
}) })
]; ];
system.checks = [ pkgs.snapshot_manager_tests ];
systemd = { systemd = {
services.snapshot_manager = { services.snapshot_manager = {
description = "ZFS Snapshot Manager"; description = "ZFS Snapshot Manager";
+1 -1
View File
@@ -14,7 +14,7 @@ DEFAULT_BASE_BRANCH = "main"
DEFAULT_BRANCH = "automation/update-flake-lock" DEFAULT_BRANCH = "automation/update-flake-lock"
DEFAULT_GITEA_URL = "https://gitea.tmmworkshop.com" DEFAULT_GITEA_URL = "https://gitea.tmmworkshop.com"
PR_LABELS = ["dependencies", "automated", "flake_lock_update"] PR_LABELS = ["dependencies", "automated", "flake_lock_update"]
PR_CHECK_WORKFLOWS = ["build_systems.yml", "treefmt.yml", "pytest.yml"] PR_CHECK_WORKFLOWS = ["build_systems.yml", "treefmt.yml"]
PR_TITLE = "Update flake.lock" PR_TITLE = "Update flake.lock"
PR_BODY = "Automated flake.lock update." PR_BODY = "Automated flake.lock update."
+29 -6
View File
@@ -6,11 +6,7 @@
let let
vars = import ../vars.nix; vars = import ../vars.nix;
stateDir = "${vars.services}/gems"; stateDir = "${vars.services}/gems";
in gemsPackages =
{
nixpkgs.overlays = [
(final: _prev: {
gems_python = final.python314.withPackages (
ps: with ps; [ ps: with ps; [
fastapi fastapi
jinja2 jinja2
@@ -19,11 +15,38 @@ in
python-multipart python-multipart
typer typer
uvicorn uvicorn
] ];
in
{
nixpkgs.overlays = [
(final: _prev: {
gems_python = final.python314.withPackages gemsPackages;
gems_test_python = final.python314.withPackages (
ps:
gemsPackages ps
++ (with ps; [
httpx
pytest
pytest-asyncio
pytest-xdist
])
); );
gems_tests =
final.runCommand "gems-tests"
{
nativeBuildInputs = [ final.gems_test_python ];
}
''
export HOME="$TMPDIR"
cd ${inputs.self}
pytest -o cache_dir="$TMPDIR/pytest-cache" tests/gems
touch "$out"
'';
}) })
]; ];
system.checks = [ pkgs.gems_tests ];
users.groups.gems = { }; users.groups.gems = { };
users.users.gems = { users.users.gems = {
isSystemUser = true; isSystemUser = true;