Add testing infrastructure

This commit is contained in:
Simon Bruder 2024-07-27 20:45:17 +02:00
parent 6e4e8d3d93
commit 2e39ef952b
Signed by: simon
GPG key ID: 347FF8699CDA0776
4 changed files with 78 additions and 15 deletions

View file

@ -20,7 +20,7 @@ jobs:
git config --unset "http.${GITHUB_SERVER_URL}/.extraHeader" git config --unset "http.${GITHUB_SERVER_URL}/.extraHeader"
git lfs install --local git lfs install --local
git lfs pull git lfs pull
- name: Build - name: Build and test
run: nix build -L .#li7y .#li7y-oci run: nix build -L .#li7y .#li7y-oci
- name: Push OCI image - name: Push OCI image
if: github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'

1
.gitignore vendored
View file

@ -3,5 +3,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
/target /target
/.tarpaulin_target
result* result*
.pre-commit-config.yaml .pre-commit-config.yaml

16
.tarpaulin.toml Normal file
View file

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
[default]
# Tarpaulin uses custom options
# that are incompatible with the default options.
# This sets a different target directory,
# so the files from tarpaulin do not interfere with the regular outputs.
target-dir = ".tarpaulin_target"
# Do not recompile everything on every run
skip-clean = true
[report]
out = ["Html"]
output-dir = "target/tarpaulin"

View file

@ -74,12 +74,57 @@
}; };
}; };
packages = rec { packages =
li7y = naersk'.buildPackage { let
# naersk does not easily allow overrideAttrs
commonNaerskConfigurarion = {
src = self; src = self;
checkInputs = with pkgs; [
postgresql
postgresqlTestHook
];
# otherwise the deps derivation is also tested (which just wastes time as there are no tests)
overrideMain = (o: o // {
doCheck = true;
});
# tests need to be able to create and drop databases
postgresqlTestUserOptions = "LOGIN SUPERUSER";
postgresqlTestSetupPost = ''
export DATABASE_URL="postgres://''${PGUSER}/''${PGDATABASE}?port=5432&host=''${PGHOST}"
'';
# Otherwise SQLx tries to infer the databse schema from an empty database
# (as it can only run the migrations once the test binary is built).
# Also, this enforces that the full query cache is included in the repository.
SQLX_OFFLINE = true;
}; };
in
rec {
li7y = naersk'.buildPackage commonNaerskConfigurarion;
default = li7y; default = li7y;
li7y-tarpaulin = naersk'.buildPackage (commonNaerskConfigurarion // {
name = "li7y-tarpaulin";
checkInputs = commonNaerskConfigurarion.checkInputs ++ (with pkgs; [
cargo-tarpaulin
]);
dontBuild = true;
singleStep = true; # tarpaulin uses different options anyway
cargoTestCommands = _: [ "cargo tarpaulin" ];
postInstall = ''
rm -r $out
cp -r target/tarpaulin $out
'';
});
li7y-oci = pkgs.dockerTools.buildLayeredImage { li7y-oci = pkgs.dockerTools.buildLayeredImage {
name = "li7y"; name = "li7y";
tag = "latest"; tag = "latest";
@ -99,6 +144,7 @@
rustPackageDev rustPackageDev
] ++ (with pkgs; [ ] ++ (with pkgs; [
cargo-deny cargo-deny
cargo-tarpaulin
cargo-watch cargo-watch
clippy clippy
graphviz graphviz