From 89a05909a4fb393864a8aa752f6979dd9aaa2898 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 30 Mar 2025 21:09:16 +0900 Subject: test: move test program to sandbox directory This prepares for the separation of app and sandbox tests. Signed-off-by: Ophestra --- test/configuration.nix | 32 +------------------------------- test/main.go | 39 --------------------------------------- test/sandbox/tool/main.go | 39 +++++++++++++++++++++++++++++++++++++++ test/sandbox/tool/package.nix | 30 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 test/main.go create mode 100644 test/sandbox/tool/main.go create mode 100644 test/sandbox/tool/package.nix (limited to 'test') diff --git a/test/configuration.nix b/test/configuration.nix index 93f1b39c..96b87a9d 100644 --- a/test/configuration.nix +++ b/test/configuration.nix @@ -5,37 +5,7 @@ ... }: let - testProgram = - let - inherit (pkgs) - buildGoModule - pkg-config - util-linux - ; - in - buildGoModule rec { - pname = "check-sandbox"; - inherit (config.environment.fortify.package) version; - - src = builtins.path { - name = "${pname}-src"; - path = lib.cleanSource ./.; - filter = path: type: (type == "directory" && lib.hasSuffix "sandbox" path) || (type == "regular" && lib.hasSuffix ".go" path); - }; - vendorHash = null; - - buildInputs = [ util-linux ]; - nativeBuildInputs = [ pkg-config ]; - - preBuild = '' - go mod init git.gensokyo.uk/security/fortify/test >& /dev/null - ''; - - postInstall = '' - mv $out/bin/test $out/bin/fortify-test - ''; - }; - + testProgram = pkgs.callPackage ./sandbox/tool/package.nix { inherit (config.environment.fortify.package) version; }; testCases = import ./sandbox/case lib testProgram; in { diff --git a/test/main.go b/test/main.go deleted file mode 100644 index 4c639b28..00000000 --- a/test/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "log" - "os" - "strconv" - "strings" - - "git.gensokyo.uk/security/fortify/test/sandbox" -) - -func main() { - log.SetFlags(0) - log.SetPrefix("test: ") - - if len(os.Args) < 2 { - log.Fatal("invalid argument") - } - - switch os.Args[1] { - case "filter": - if len(os.Args) != 4 { - log.Fatal("invalid argument") - } - - if pid, err := strconv.Atoi(strings.TrimSpace(os.Args[2])); err != nil { - log.Fatalf("%s", err) - } else if pid < 1 { - log.Fatalf("%d out of range", pid) - } else { - sandbox.MustCheckFilter(pid, os.Args[3]) - return - } - - default: - (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok") - return - } -} diff --git a/test/sandbox/tool/main.go b/test/sandbox/tool/main.go new file mode 100644 index 00000000..4c639b28 --- /dev/null +++ b/test/sandbox/tool/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "log" + "os" + "strconv" + "strings" + + "git.gensokyo.uk/security/fortify/test/sandbox" +) + +func main() { + log.SetFlags(0) + log.SetPrefix("test: ") + + if len(os.Args) < 2 { + log.Fatal("invalid argument") + } + + switch os.Args[1] { + case "filter": + if len(os.Args) != 4 { + log.Fatal("invalid argument") + } + + if pid, err := strconv.Atoi(strings.TrimSpace(os.Args[2])); err != nil { + log.Fatalf("%s", err) + } else if pid < 1 { + log.Fatalf("%d out of range", pid) + } else { + sandbox.MustCheckFilter(pid, os.Args[3]) + return + } + + default: + (&sandbox.T{FS: os.DirFS("/")}).MustCheckFile(os.Args[1], "/tmp/sandbox-ok") + return + } +} diff --git a/test/sandbox/tool/package.nix b/test/sandbox/tool/package.nix new file mode 100644 index 00000000..7cc3472e --- /dev/null +++ b/test/sandbox/tool/package.nix @@ -0,0 +1,30 @@ +{ + lib, + buildGoModule, + pkg-config, + util-linux, + + version, +}: +buildGoModule rec { + pname = "check-sandbox"; + inherit version; + + src = builtins.path { + name = "${pname}-src"; + path = lib.cleanSource ../.; + filter = path: type: (type == "directory") || (type == "regular" && lib.hasSuffix ".go" path); + }; + vendorHash = null; + + buildInputs = [ util-linux ]; + nativeBuildInputs = [ pkg-config ]; + + preBuild = '' + go mod init git.gensokyo.uk/security/fortify/test/sandbox >& /dev/null + ''; + + postInstall = '' + mv $out/bin/tool $out/bin/fortify-test + ''; +} -- cgit v1.3.1