feat: +checks flake output
This commit is contained in:
3
test/default.nix
Normal file
3
test/default.nix
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{ system, inputs, self, pkgs, flake }:
|
||||||
|
(import ./package { inherit system inputs self pkgs; })
|
||||||
|
|
||||||
0
test/hardware/default.nix
Normal file
0
test/hardware/default.nix
Normal file
17
test/hardware/lenovo-ideapad-15arh7.nix
Normal file
17
test/hardware/lenovo-ideapad-15arh7.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{ self, inputs, system, ... }: let
|
||||||
|
mkSys = system: opts:
|
||||||
|
(inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
inherit system;
|
||||||
|
modules = [
|
||||||
|
self.nixosModules.hectic
|
||||||
|
{ hectic.hardware.lenovo-ideapad-15arh7 = opts; }
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
cases = {
|
||||||
|
#enable = { enable = true; };
|
||||||
|
#disabled = { enable = false; };
|
||||||
|
#customFoo = { enable = true; foo = "bar"; };
|
||||||
|
};
|
||||||
|
in inputs.nixpkgs.lib.mapAttrs
|
||||||
|
(name: opts: (mkSys system opts).config.system.build.toplevel) cases
|
||||||
1
test/package/default.nix
Normal file
1
test/package/default.nix
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ system, inputs, self, pkgs }: (import ./migrator { inherit system inputs self pkgs; })
|
||||||
44
test/package/migrator/default.nix
Normal file
44
test/package/migrator/default.nix
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{ inputs, self, pkgs, system, ... }: let
|
||||||
|
lib = inputs.nixpkgs.lib;
|
||||||
|
|
||||||
|
# turn anything under ./test into a derivation that exposes $out/run.sh
|
||||||
|
mkTestDrv = name: type:
|
||||||
|
if type == "directory" then
|
||||||
|
pkgs.runCommand "test-${name}" {} ''
|
||||||
|
if ! [ -f ${./test + "/${name}" + /run.sh} ]; then
|
||||||
|
echo no run.sh in test/${name}
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$out"
|
||||||
|
cp -r ${./test + "/${name}"}/* "$out/"
|
||||||
|
chmod +x "$out/run.sh"
|
||||||
|
''
|
||||||
|
else if lib.hasSuffix ".sh" name then
|
||||||
|
pkgs.runCommand "test-${lib.removeSuffix ".sh" name}" {} ''
|
||||||
|
mkdir -p "$out"
|
||||||
|
install -Dm755 ${./test + "/${name}"} "$out/run.sh"
|
||||||
|
''
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
|
||||||
|
testDir = builtins.readDir ./test;
|
||||||
|
|
||||||
|
# attrset: testName -> drv with run.sh
|
||||||
|
testDrvs =
|
||||||
|
lib.mapAttrs' (n: v:
|
||||||
|
lib.nameValuePair (lib.removeSuffix ".sh" n) v
|
||||||
|
) (lib.filterAttrs (_: v: v != null)
|
||||||
|
(lib.mapAttrs (n: t: mkTestDrv n t) testDir));
|
||||||
|
|
||||||
|
migrator = self.packages.${system}.migrator;
|
||||||
|
mkPgTest = testName: testDrv: pkgs.runCommand "migrator-test-${testName}"
|
||||||
|
{
|
||||||
|
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
||||||
|
buildInputs = [ migrator pkgs.postgresql ];
|
||||||
|
} ''
|
||||||
|
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
||||||
|
test=${testDrv}
|
||||||
|
${builtins.readFile ./lauch.sh}
|
||||||
|
'';
|
||||||
|
in builtins.trace testDir (lib.mapAttrs (name: drv: mkPgTest name drv) testDrvs)
|
||||||
68
test/package/migrator/lauch.sh
Normal file
68
test/package/migrator/lauch.sh
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
|
||||||
|
# $out - nix derivation output
|
||||||
|
# $test - test and assertion file
|
||||||
|
|
||||||
|
test_derivation="$(basename "$test")"
|
||||||
|
test_name="${test_derivation#*-*-}"
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
root_dir="$(dirname $0)"
|
||||||
|
|
||||||
|
HECTIC_LOG=
|
||||||
|
|
||||||
|
# save path to pg_ctl in case $PATH will change
|
||||||
|
PG_CTL="$(command -v pg_ctl)"
|
||||||
|
cleanup() {
|
||||||
|
"$PG_CTL" -D "$data" -m fast -w stop
|
||||||
|
}
|
||||||
|
|
||||||
|
log info 'start test pipeline'
|
||||||
|
|
||||||
|
# temp dirs
|
||||||
|
wd="$PWD"
|
||||||
|
data="$wd/data"
|
||||||
|
sockdir="$wd/sock"
|
||||||
|
db="testdb"
|
||||||
|
mkdir -p "$data" "$sockdir"
|
||||||
|
|
||||||
|
# initdb
|
||||||
|
initdb -D "$data" --no-locale -E UTF8 >/dev/null
|
||||||
|
|
||||||
|
# trust local auth for the test
|
||||||
|
{
|
||||||
|
echo "unix_socket_directories = '$sockdir'"
|
||||||
|
echo "listen_addresses = ''"
|
||||||
|
} >> "$data/postgresql.conf"
|
||||||
|
sed -i "1ilocal all all trust" "$data/pg_hba.conf"
|
||||||
|
|
||||||
|
# start cluster
|
||||||
|
pg_ctl -D "$data" -o "-F" -w start
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
user="$(id -un)"
|
||||||
|
|
||||||
|
# bootstrap DB
|
||||||
|
createdb -h "$sockdir" -U "$user" "$db"
|
||||||
|
|
||||||
|
psql -h "$sockdir" -d testdb -v ON_ERROR_STOP=1 -c 'select 1;' >/dev/null
|
||||||
|
|
||||||
|
export PGHOST="$sockdir"
|
||||||
|
export PGPORT=5432
|
||||||
|
export PGUSER="$user"
|
||||||
|
export PGDATABASE="$db"
|
||||||
|
|
||||||
|
DATABASE_URL="postgresql://${PGUSER}@/${PGDATABASE}?host=${PGHOST}&port=${PGPORT}"
|
||||||
|
export DATABASE_URL
|
||||||
|
|
||||||
|
log info "run test ${WHITE}${test_name}${NC}"
|
||||||
|
|
||||||
|
# run test
|
||||||
|
. "${test}/run.sh"
|
||||||
|
|
||||||
|
log info "finish test pipeline"
|
||||||
|
|
||||||
|
# success marker for Nix
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
mkdir -p "$out"
|
||||||
21
test/package/migrator/test/mising-psql.sh
Normal file
21
test/package/migrator/test/mising-psql.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# remove psql from $PATH
|
||||||
|
dir=$(dirname -- "$(command -v psql)")
|
||||||
|
PATH=$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: -v d="$dir" '$0!=d{print}')
|
||||||
|
PATH=${PATH%:}
|
||||||
|
# clear lookup cache
|
||||||
|
hash -r 2>/dev/null || true
|
||||||
|
|
||||||
|
# temporary disable break on errors, coz in this test we check error-handling scenario
|
||||||
|
set +e
|
||||||
|
# try to run migrator without installed psql
|
||||||
|
migrator 2>/dev/null
|
||||||
|
migrator_error_code=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
log debug "migrator error code: $migrator_error_code"
|
||||||
|
|
||||||
|
if [ "$migrator_error_code" -eq 127 ]; then
|
||||||
|
log notice "test passed"
|
||||||
|
else
|
||||||
|
log error "test failed"
|
||||||
|
fi
|
||||||
0
test/package/migrator/test/placeholder
Normal file
0
test/package/migrator/test/placeholder
Normal file
Reference in New Issue
Block a user