From 4dae10d2d18841d2c6211b6b2d71c0b66c730eef Mon Sep 17 00:00:00 2001 From: Matthew Conolly Date: Fri, 25 Aug 2023 15:04:12 -0700 Subject: [PATCH] wakebox: add some unit tests (#1404) --- tests/wakebox/false/.wakeroot | 1 + tests/wakebox/false/fail.sh | 6 ++++++ tests/wakebox/false/input.json | 16 ++++++++++++++++ tests/wakebox/isolate-retcode/.wakeroot | 1 + tests/wakebox/isolate-retcode/input.json | 16 ++++++++++++++++ tests/wakebox/isolate-retcode/pass.sh | 14 ++++++++++++++ tests/wakebox/true/.wakeroot | 1 + tests/wakebox/true/input.json | 16 ++++++++++++++++ tests/wakebox/true/pass.sh | 6 ++++++ 9 files changed, 77 insertions(+) create mode 100644 tests/wakebox/false/.wakeroot create mode 100755 tests/wakebox/false/fail.sh create mode 100644 tests/wakebox/false/input.json create mode 100644 tests/wakebox/isolate-retcode/.wakeroot create mode 100644 tests/wakebox/isolate-retcode/input.json create mode 100755 tests/wakebox/isolate-retcode/pass.sh create mode 100644 tests/wakebox/true/.wakeroot create mode 100644 tests/wakebox/true/input.json create mode 100755 tests/wakebox/true/pass.sh diff --git a/tests/wakebox/false/.wakeroot b/tests/wakebox/false/.wakeroot new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/wakebox/false/.wakeroot @@ -0,0 +1 @@ + diff --git a/tests/wakebox/false/fail.sh b/tests/wakebox/false/fail.sh new file mode 100755 index 000000000..73714b1a1 --- /dev/null +++ b/tests/wakebox/false/fail.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# It's not valid to call wakebox with an empty PATH. +# So we fill PATH with some typical values. +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin + +${1}/wakebox -p input.json diff --git a/tests/wakebox/false/input.json b/tests/wakebox/false/input.json new file mode 100644 index 000000000..6b28e3571 --- /dev/null +++ b/tests/wakebox/false/input.json @@ -0,0 +1,16 @@ +{ + "command": [ + "false" + ], + "environment": [ + "USER=root", + "HOME=/root", + "PATH=/usr/bin:/bin:/usr/sbin:/sbin" + ], + "directory": ".", + "stdin": "", + "user-id": 0, + "group-id": 0, + "mount-ops": [], + "visible": [] +} diff --git a/tests/wakebox/isolate-retcode/.wakeroot b/tests/wakebox/isolate-retcode/.wakeroot new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/wakebox/isolate-retcode/.wakeroot @@ -0,0 +1 @@ + diff --git a/tests/wakebox/isolate-retcode/input.json b/tests/wakebox/isolate-retcode/input.json new file mode 100644 index 000000000..14cd8e4d8 --- /dev/null +++ b/tests/wakebox/isolate-retcode/input.json @@ -0,0 +1,16 @@ +{ + "command": [ + "sh", "-c", "exit 97" + ], + "environment": [ + "USER=root", + "HOME=/root", + "PATH=/usr/bin:/bin:/usr/sbin:/sbin" + ], + "directory": ".", + "stdin": "", + "user-id": 0, + "group-id": 0, + "mount-ops": [], + "visible": [] +} diff --git a/tests/wakebox/isolate-retcode/pass.sh b/tests/wakebox/isolate-retcode/pass.sh new file mode 100755 index 000000000..57199ef6b --- /dev/null +++ b/tests/wakebox/isolate-retcode/pass.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# It's not valid to call wakebox with an empty PATH. +# So we fill PATH with some typical values. +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin + + +${1}/wakebox -I -p input.json -o result.json +RET=$? + +[ $RET -ne 0 ] && exit 99 + +[ $(cat result.json | jq .usage.status) -ne 97 ] && exit 98 + +exit 0 diff --git a/tests/wakebox/true/.wakeroot b/tests/wakebox/true/.wakeroot new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/wakebox/true/.wakeroot @@ -0,0 +1 @@ + diff --git a/tests/wakebox/true/input.json b/tests/wakebox/true/input.json new file mode 100644 index 000000000..b442988ff --- /dev/null +++ b/tests/wakebox/true/input.json @@ -0,0 +1,16 @@ +{ + "command": [ + "true" + ], + "environment": [ + "USER=root", + "HOME=/root", + "PATH=/usr/bin:/bin:/usr/sbin:/sbin" + ], + "directory": ".", + "stdin": "", + "user-id": 0, + "group-id": 0, + "mount-ops": [], + "visible": [] +} diff --git a/tests/wakebox/true/pass.sh b/tests/wakebox/true/pass.sh new file mode 100755 index 000000000..73714b1a1 --- /dev/null +++ b/tests/wakebox/true/pass.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# It's not valid to call wakebox with an empty PATH. +# So we fill PATH with some typical values. +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin + +${1}/wakebox -p input.json