From d97a03c7c6d723587b6c35c8cbd8b69101d7e93f Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 27 Mar 2025 23:43:13 +0900 Subject: [PATCH] test/sandbox: separate test tool source This improves readability and allows gofmt to format the file. Signed-off-by: Ophestra --- test/configuration.nix | 10 +--------- test/sandbox/assert.nix | 30 ------------------------------ test/sandbox/case/default.nix | 34 +++++++++++++++++++++++++--------- test/sandbox/case/main.go | 9 +++++++++ 4 files changed, 35 insertions(+), 48 deletions(-) delete mode 100644 test/sandbox/assert.nix create mode 100644 test/sandbox/case/main.go diff --git a/test/configuration.nix b/test/configuration.nix index 75439fc..6f94170 100644 --- a/test/configuration.nix +++ b/test/configuration.nix @@ -5,15 +5,7 @@ ... }: let - testCases = import ./sandbox/case { - inherit (pkgs) - lib - callPackage - writeText - foot - ; - inherit (config.environment.fortify.package) version; - }; + testCases = import ./sandbox/case pkgs config.environment.fortify.package.version; in { users.users = { diff --git a/test/sandbox/assert.nix b/test/sandbox/assert.nix deleted file mode 100644 index 7871108..0000000 --- a/test/sandbox/assert.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - writeText, - buildGoModule, - pkg-config, - util-linux, - - version, -}: -buildGoModule { - pname = "check-sandbox"; - inherit version; - - src = ../.; - vendorHash = null; - - buildInputs = [ util-linux ]; - nativeBuildInputs = [ pkg-config ]; - - preBuild = '' - go mod init git.gensokyo.uk/security/fortify/test >& /dev/null - cp ${writeText "main.go" '' - package main - - import "os" - import "git.gensokyo.uk/security/fortify/test/sandbox" - - func main() { (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok") } - ''} main.go - ''; -} diff --git a/test/sandbox/case/default.nix b/test/sandbox/case/default.nix index d00eabf..c4bfb40 100644 --- a/test/sandbox/case/default.nix +++ b/test/sandbox/case/default.nix @@ -1,12 +1,14 @@ -{ - lib, - callPackage, - writeText, - foot, - - version, -}: +pkgs: version: let + inherit (pkgs) + lib + writeText + buildGoModule + pkg-config + util-linux + foot + ; + fs = mode: dir: data: { mode = lib.fromHexString mode; inherit @@ -30,7 +32,21 @@ let ; }; - checkSandbox = callPackage ../assert.nix { inherit version; }; + checkSandbox = buildGoModule { + pname = "check-sandbox"; + inherit version; + + src = ../../.; + vendorHash = null; + + buildInputs = [ util-linux ]; + nativeBuildInputs = [ pkg-config ]; + + preBuild = '' + go mod init git.gensokyo.uk/security/fortify/test >& /dev/null + cp ${./main.go} main.go + ''; + }; callTestCase = path: diff --git a/test/sandbox/case/main.go b/test/sandbox/case/main.go new file mode 100644 index 0000000..59c80ef --- /dev/null +++ b/test/sandbox/case/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "os" + + "git.gensokyo.uk/security/fortify/test/sandbox" +) + +func main() { (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok") }