open-nomad/drivers/docker/driver_darwin_test.go
Tim Gross cc9b480996
testing: setting env var incompatible with parallel tests (#14405)
Neither the `os.Setenv` nor `t.Setenv` helper are safe to use in parallel tests
because environment variables are process-global. The stdlib panics if you try
to do this. Remove the `ci.Parallel()` call from all tests where we're setting
environment variables.
2022-08-30 14:49:03 -04:00

29 lines
612 B
Go

//go:build darwin
package docker
import (
"fmt"
"os"
"testing"
"time"
)
// TestMain is a hacky test entrypoint to set temp directory to a path that can
// be mounted into Docker containers on macOS without needing dev performing
// special setup.
//
// macOS sets tempdir as `/var`, which Docker does not allowlist as a path that
// can be bind-mounted.
func TestMain(m *testing.M) {
tmpdir := fmt.Sprintf("/tmp/nomad-docker-tests-%d", time.Now().Unix())
os.Setenv("TMPDIR", os.Getenv("TMPDIR"))
os.Setenv("TMPDIR", tmpdir)
os.MkdirAll(tmpdir, 0700)
defer os.RemoveAll(tmpdir)
os.Exit(m.Run())
}