package bazel import ( "os" "testing" ) func TestNewTestTmpDir(t *testing.T) { prefix := "testy-boi" tmpdir, err := NewTestTmpDir(prefix) if err != nil { t.Errorf("When creating temp dir %s got error %s", prefix, err) } // Check that the tempdir actually exist if _, err := os.Stat(tmpdir); err != nil { t.Errorf("New tempdir (%s) not created. Got error %s", tmpdir, err) } } func TestTestTmpDir(t *testing.T) { d := ResolveTestTmpDir() if d == "" { t.Error("TestTmpDir (TEST_TMPDIR) was left empty") } // This will return the same value if ran outside of Bazel, so skip if !IsBazelTest() { return } os.Unsetenv(TestTmpDir) osDir := ResolveTestTmpDir() if osDir == d { t.Error("Shouldn't have gotten same value after unsetting bazel sandbox variable", "sandbox dir", d, "os dir", osDir, ) } if osDir == "" { t.Error("Failed to resolve OS temp directory") } }