v/testutils/setup.go

23 lines
433 B
Go
Raw Permalink Normal View History

package testutils
import (
"os"
"testing"
)
// SetupAndCleanupEnvironment sets up a test directory and
// environment variables before the test and returns a cleanup
// function that can be deferred to cleanup any changes to the
// system.
func SetupAndCleanupEnvironment(t *testing.T) func() {
os.Setenv("V_ROOT", t.TempDir())
temporaryWd := t.TempDir()
os.Chdir(temporaryWd)
return func() {
os.Unsetenv("V_ROOT")
}
}