github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/drivers/docker/driver_darwin_test.go (about)

     1  //go:build darwin
     2  
     3  package docker
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"testing"
     9  	"time"
    10  )
    11  
    12  // TestMain is a hacky test entrypoint to set temp directory to a path that can
    13  // be mounted into Docker containers on macOS without needing dev performing
    14  // special setup.
    15  //
    16  // macOS sets tempdir as `/var`, which Docker does not allowlist as a path that
    17  // can be bind-mounted.
    18  func TestMain(m *testing.M) {
    19  	tmpdir := fmt.Sprintf("/tmp/nomad-docker-tests-%d", time.Now().Unix())
    20  
    21  	os.Setenv("TMPDIR", os.Getenv("TMPDIR"))
    22  	os.Setenv("TMPDIR", tmpdir)
    23  
    24  	os.MkdirAll(tmpdir, 0700)
    25  	defer os.RemoveAll(tmpdir)
    26  
    27  	os.Exit(m.Run())
    28  }