test/sandbox: pass want file as argument
All checks were successful
Test / Create distribution (push) Successful in 25s
Test / Fpkg (push) Successful in 33s
Test / Fortify (push) Successful in 2m7s
Test / Data race detector (push) Successful in 2m36s
Test / Flake checks (push) Successful in 49s

This avoids building the check program multiple times.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-03-23 15:00:59 +09:00
parent 75e0c5d406
commit 2d379b5a38
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
3 changed files with 16 additions and 22 deletions

View File

@ -3,22 +3,9 @@
buildGoModule, buildGoModule,
version, version,
name,
want,
}: }:
let
wantFile = writeText "fortify-${name}-want.json" (builtins.toJSON want);
mainFile = writeText "main.go" ''
package main
import "os"
import "git.gensokyo.uk/security/fortify/test/sandbox"
func main() { (&sandbox.T{FS: os.DirFS("/"), PMountsPath: "/.fortify/mounts"}).MustCheckFile("${wantFile}") }
'';
in
buildGoModule { buildGoModule {
pname = "fortify-${name}-check-sandbox"; pname = "check-sandbox";
inherit version; inherit version;
src = ../.; src = ../.;
@ -26,6 +13,13 @@ buildGoModule {
preBuild = '' preBuild = ''
go mod init git.gensokyo.uk/security/fortify/test >& /dev/null go mod init git.gensokyo.uk/security/fortify/test >& /dev/null
cp ${mainFile} main.go cp ${writeText "main.go" ''
package main
import "os"
import "git.gensokyo.uk/security/fortify/test/sandbox"
func main() { (&sandbox.T{FS: os.DirFS("/"), PMountsPath: "/.fortify/mounts"}).MustCheckFile(os.Args[1]) }
''} main.go
''; '';
} }

View File

@ -25,6 +25,8 @@ let
; ;
}; };
checkSandbox = callPackage ../. { inherit version; };
callTestCase = callTestCase =
path: path:
let let
@ -40,10 +42,7 @@ let
verbose = true; verbose = true;
share = foot; share = foot;
packages = [ ]; packages = [ ];
command = "${callPackage ../. { command = builtins.toString (checkSandbox tc.name tc.want);
inherit (tc) name want;
inherit version;
}}";
extraPaths = [ extraPaths = [
{ {
src = "/proc/mounts"; src = "/proc/mounts";

View File

@ -1,13 +1,14 @@
{ {
writeShellScript, writeShellScript,
writeText,
callPackage, callPackage,
name,
version, version,
want,
}: }:
name: want:
writeShellScript "fortify-${name}-check-sandbox-script" '' writeShellScript "fortify-${name}-check-sandbox-script" ''
set -e set -e
${callPackage ./assert.nix { inherit name version want; }}/bin/test ${callPackage ./assert.nix { inherit version; }}/bin/test \
${writeText "fortify-${name}-want.json" (builtins.toJSON want)}
touch /tmp/sandbox-ok touch /tmp/sandbox-ok
'' ''