2015-04-08 13:43:55 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2015-04-09 08:26:26 +00:00
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"testing"
|
2015-04-08 13:43:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathExpansion(t *testing.T) {
|
|
|
|
|
2015-04-09 08:26:26 +00:00
|
|
|
user, _ := user.Current()
|
2015-04-08 13:43:55 +00:00
|
|
|
|
2015-04-09 08:26:26 +00:00
|
|
|
tests := map[string]string{
|
|
|
|
"/home/someuser/tmp": "/home/someuser/tmp",
|
|
|
|
"~/tmp": user.HomeDir + "/tmp",
|
|
|
|
"$DDDXXX/a/b": "/tmp/a/b",
|
|
|
|
"/a/b/": "/a/b",
|
|
|
|
}
|
2015-04-08 13:43:55 +00:00
|
|
|
|
2015-04-09 08:26:26 +00:00
|
|
|
os.Setenv("DDDXXX", "/tmp")
|
2015-04-08 13:43:55 +00:00
|
|
|
|
2015-04-09 08:26:26 +00:00
|
|
|
for test, expected := range tests {
|
|
|
|
got := expandPath(test)
|
|
|
|
if got != expected {
|
|
|
|
t.Errorf("test %s, got %s, expected %s\n", test, got, expected)
|
|
|
|
}
|
|
|
|
}
|
2015-04-08 13:43:55 +00:00
|
|
|
}
|