...

Source file src/edge-infra.dev/pkg/lib/build/bazel/path_test.go

Documentation: edge-infra.dev/pkg/lib/build/bazel

     1  package bazel
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func TestNewTestTmpDir(t *testing.T) {
     9  	prefix := "testy-boi"
    10  	tmpdir, err := NewTestTmpDir(prefix)
    11  	if err != nil {
    12  		t.Errorf("When creating temp dir %s got error %s", prefix, err)
    13  	}
    14  
    15  	// Check that the tempdir actually exist
    16  	if _, err := os.Stat(tmpdir); err != nil {
    17  		t.Errorf("New tempdir (%s) not created. Got error %s", tmpdir, err)
    18  	}
    19  }
    20  
    21  func TestTestTmpDir(t *testing.T) {
    22  	d := ResolveTestTmpDir()
    23  	if d == "" {
    24  		t.Error("TestTmpDir (TEST_TMPDIR) was left empty")
    25  	}
    26  
    27  	// This will return the same value if ran outside of Bazel, so skip
    28  	if !IsBazelTest() {
    29  		return
    30  	}
    31  
    32  	os.Unsetenv(TestTmpDir)
    33  	osDir := ResolveTestTmpDir()
    34  	if osDir == d {
    35  		t.Error("Shouldn't have gotten same value after unsetting bazel sandbox variable",
    36  			"sandbox dir", d,
    37  			"os dir", osDir,
    38  		)
    39  	}
    40  	if osDir == "" {
    41  		t.Error("Failed to resolve OS temp directory")
    42  	}
    43  }
    44  

View as plain text