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 lfs install --local
git lfs pull
- name: Build
- name: Build and test
run: nix build -L .#li7y .#li7y-oci
- name: Push OCI image
if: github.ref == 'refs/heads/master'

1
.gitignore vendored
View file

@ -3,5 +3,6 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
/target
/.tarpaulin_target
result*
.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,31 +74,77 @@
};
};
packages = rec {
li7y = naersk'.buildPackage {
src = self;
};
default = li7y;
packages =
let
# naersk does not easily allow overrideAttrs
commonNaerskConfigurarion = {
src = self;
li7y-oci = pkgs.dockerTools.buildLayeredImage {
name = "li7y";
tag = "latest";
checkInputs = with pkgs; [
postgresql
postgresqlTestHook
];
contents = [
li7y
];
# otherwise the deps derivation is also tested (which just wastes time as there are no tests)
overrideMain = (o: o // {
doCheck = true;
});
config = {
Cmd = [ "${li7y}/bin/li7y" ];
# 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;
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 {
name = "li7y";
tag = "latest";
contents = [
li7y
];
config = {
Cmd = [ "${li7y}/bin/li7y" ];
};
};
};
};
devShells.default = pkgs.mkShell {
buildInputs = [
rustPackageDev
] ++ (with pkgs; [
cargo-deny
cargo-tarpaulin
cargo-watch
clippy
graphviz