From 997cc95aa85e5f1eb31b38723ce2e69171929eb4 Mon Sep 17 00:00:00 2001 From: Bill Robbins Date: Fri, 6 Feb 2015 15:20:54 -0600 Subject: [PATCH] handle TMPDIR not existing for tests --- viper_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/viper_test.go b/viper_test.go index 0bbe84f..1f4d684 100644 --- a/viper_test.go +++ b/viper_test.go @@ -14,6 +14,7 @@ import ( "time" "os/exec" "path" + "path/filepath" "io/ioutil" "github.com/spf13/pflag" @@ -390,7 +391,7 @@ func TestFindAllConfigPaths(t *testing.T){ command.Run() } - assert.Equal(t,expected,found,"All files should exist") + assert.Equal(t,expected,removeDuplicates(found),"All files should exist") } func generateCascadingTests(v2 *viper, file_name string) []string { @@ -398,6 +399,9 @@ func generateCascadingTests(v2 *viper, file_name string) []string { v2.SetConfigName(file_name) tmp := os.Getenv("TMPDIR") + if( tmp == ""){ + tmp,_ = filepath.Abs(filepath.Dir("./")) + } // $TMPDIR/a > $TMPDIR/b > %TMPDIR paths := []string{path.Join(tmp,"a"),path.Join(tmp,"b"),tmp} @@ -443,3 +447,15 @@ func generateCascadingTests(v2 *viper, file_name string) []string { return expected } + +func removeDuplicates(a []string) []string { + result := []string{} + seen := map[string]string{} + for _, val := range a { + if _, ok := seen[val]; !ok { + result = append(result, val) + seen[val] = val + } + } + return result +}