Add ./go/tests.sh

This commit is contained in:
Brian Picciano 2024-10-05 21:12:29 +02:00
parent 48611df2cb
commit 168b65ea1d
3 changed files with 53 additions and 38 deletions

View File

@ -1,5 +1,4 @@
{
buildSystem ? builtins.currentSystem,
hostSystem ? buildSystem,
pkgsNix ? (import ./nix/pkgs.nix),
@ -106,10 +105,7 @@ in rec {
'';
};
appDir = pkgs.stdenv.mkDerivation {
name = "isle-AppDir";
src = pkgs.buildEnv {
appDirBase = pkgs.buildEnv {
name = "isle-AppDir-base";
paths = [
@ -119,18 +115,23 @@ in rec {
nebula
garage
pkgs.minio-client
goBinaries
] ++ (if bootstrap != null then [ rootedBootstrap ] else []);
};
appDir = pkgs.stdenv.mkDerivation {
name = "isle-AppDir";
src = appDirBase;
inherit goBinaries;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" "$out"
chmod +w "$out" -R
cd "$out"
cp ./bin/entrypoint ./AppRun
cp $goBinaries/bin/entrypoint ./AppRun
'';
};
@ -178,4 +179,22 @@ in rec {
export SHELL=${pkgs.bash}/bin/bash
exec ${pkgs.bash}/bin/bash ${./tests}/entrypoint.sh "$@"
'';
devShell = pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.golangci-lint
(pkgs.callPackage ./nix/gowrap.nix {})
];
shellHook = ''
true # placeholder
'';
};
testShell = pkgs.mkShell {
APPDIR = appDirBase;
buildInputs = [
pkgs.go
];
};
}

17
go/test.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR" || exit
this_user="$(whoami)"
nix-shell -A testShell ../default.nix --run "
echo \"Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately\"
sudo -E capsh \\
--caps=\"cap_net_admin,cap_net_bind_service+eip cap_setpcap,cap_setuid,cap_setgid+ep\" \\
--keep=1 \\
--user=\"$this_user\" \\
--addamb=cap_net_admin \\
--addamb=cap_net_bind_service \\
-- -c 'go test $*'
"

View File

@ -1,22 +1 @@
{
buildSystem ? builtins.currentSystem,
pkgsNix ? (import ./nix/pkgs.nix),
}: let
pkgs = pkgsNix.default {
inherit buildSystem;
hostSystem = buildSystem;
};
in pkgs.mkShell {
buildInputs = [
pkgs.go
pkgs.golangci-lint
(pkgs.callPackage ./nix/gowrap.nix {})
];
shellHook = ''
true # placeholder
'';
}
{}@args: ((import ./default.nix) args).devShell