aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sandbox/assert.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-27 03:16:33 +0900
committerOphestra <cat@gensokyo.uk>2025-03-27 03:16:33 +0900
commitf8502c3ece1ff53b244326e341b166174f7f5d79 (patch)
tree896aa5ce7a03b3cd0a128da9e9414166c6184e60 /test/sandbox/assert.go
parent996b42634dba83a488d0ac67eac954c0b5582c71 (diff)
test/sandbox: check environment
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'test/sandbox/assert.go')
-rw-r--r--test/sandbox/assert.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/sandbox/assert.go b/test/sandbox/assert.go
index 3cf81ffb..3a34c736 100644
--- a/test/sandbox/assert.go
+++ b/test/sandbox/assert.go
@@ -23,6 +23,7 @@ func printf(format string, v ...any) { printfFunc(format, v...) }
func fatalf(format string, v ...any) { fatalfFunc(format, v...) }
type TestCase struct {
+ Env []string `json:"env"`
FS *FS `json:"fs"`
Mount []*MountinfoEntry `json:"mount"`
Seccomp bool `json:"seccomp"`
@@ -44,6 +45,36 @@ func (t *T) MustCheckFile(wantFilePath, markerPath string) {
}
func (t *T) MustCheck(want *TestCase) {
+ if want.Env != nil {
+ var (
+ fail bool
+ i int
+ got string
+ )
+ for i, got = range os.Environ() {
+ if i == len(want.Env) {
+ fatalf("got more than %d environment variables", len(want.Env))
+ }
+ if got != want.Env[i] {
+ fail = true
+ printf("[FAIL] %s", got)
+ } else {
+ printf("[ OK ] %s", got)
+ }
+ }
+
+ i++
+ if i != len(want.Env) {
+ fatalf("got %d environment variables, want %d", i, len(want.Env))
+ }
+
+ if fail {
+ fatalf("[FAIL] some environment variables did not match")
+ }
+ } else {
+ printf("[SKIP] skipping environ check")
+ }
+
if want.FS != nil && t.FS != nil {
if err := want.FS.Compare(".", t.FS); err != nil {
fatalf("%v", err)