| 1 |
package basedir |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestBaseDir(t *testing.T) { |
| 9 |
if Home == "" { |
| 10 |
t.Error("Home not set") |
| 11 |
} |
| 12 |
if DataHome == "" { |
| 13 |
t.Error("DataHome not set") |
| 14 |
} |
| 15 |
if ConfigHome == "" { |
| 16 |
t.Error("ConfigHome not set") |
| 17 |
} |
| 18 |
if CacheHome == "" { |
| 19 |
t.Error("CacheHome not set") |
| 20 |
} |
| 21 |
if RuntimeDir == "" { |
| 22 |
t.Error("RuntimeDir not set") |
| 23 |
} |
| 24 |
if len(DataDirs) == 0 { |
| 25 |
t.Error("DataDirs not set") |
| 26 |
} |
| 27 |
if len(ConfigDirs) == 0 { |
| 28 |
t.Error("ConfigDirs not set") |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
func TestGetPath(t *testing.T) { |
| 33 |
const notSet = "not set" |
| 34 |
if getPath("HOME", notSet) == notSet { |
| 35 |
t.Error("Couldn't get HOME") |
| 36 |
} |
| 37 |
if getPath("does_not_exist", notSet) != notSet { |
| 38 |
t.Error("does_not_exist exists") |
| 39 |
} |
| 40 |
if getPath("USER", notSet) != notSet { |
| 41 |
t.Error("USER appears to be an absolute path") |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func TestGetpathlist(t *testing.T) { |
| 46 |
if getPathList("PATH", nil) == nil { |
| 47 |
t.Error("Couldn't get PATH") |
| 48 |
} |
| 49 |
if getPathList("does_not_exist", nil) != nil { |
| 50 |
t.Error("does_not_exist exists") |
| 51 |
} |
| 52 |
err := os.Setenv("xdg_test_var", "/a:c:/a/b:d/f") |
| 53 |
if err != nil { |
| 54 |
t.Error(err) |
| 55 |
} |
| 56 |
testVar := getPathList("xdg_test_var", nil) |
| 57 |
if testVar[0] != "/a" || testVar[1] != "/a/b" { |
| 58 |
t.Error("getPathList returned relative paths") |
| 59 |
} |
| 60 |
} |