osutil: don't use host config during tests

Change-Id: I28171f0dc9c3c21c9693805781275c39ed517d25
This commit is contained in:
Brad Fitzpatrick 2014-02-23 10:00:45 -08:00
parent 8bbe100bbc
commit 99a4ee0fd3
1 changed files with 8 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package osutil
import (
"fmt"
"os"
"path/filepath"
"testing"
)
@ -60,6 +61,10 @@ func checkOpen(t *testing.T, path string) {
func TestOpenCamliIncludeNoFile(t *testing.T) {
// Test that error occurs if no such file
const notExist = "this_config_doesnt_exist.config"
defer os.Setenv("CAMLI_CONFIG_DIR", os.Getenv("CAMLI_CONFIG_DIR"))
os.Setenv("CAMLI_CONFIG_DIR", filepath.Join(os.TempDir(), "/x/y/z/not-exist"))
_, e := FindCamliInclude(notExist)
if e == nil {
t.Errorf("Successfully opened config which doesn't exist: %v", notExist)
@ -102,6 +107,9 @@ func TestOpenCamliIncludePath(t *testing.T) {
defer os.Remove("/tmp/" + name)
defer os.Setenv("CAMLI_INCLUDE_PATH", "")
defer os.Setenv("CAMLI_CONFIG_DIR", os.Getenv("CAMLI_CONFIG_DIR"))
os.Setenv("CAMLI_CONFIG_DIR", filepath.Join(os.TempDir(), "/x/y/z/not-exist"))
os.Setenv("CAMLI_INCLUDE_PATH", "/tmp")
checkOpen(t, name)