2015-04-08 08:43:55 -05:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2015-04-09 03:26:26 -05:00
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"testing"
|
2015-04-08 08:43:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPathExpansion(t *testing.T) {
|
|
|
|
|
2015-04-09 03:26:26 -05:00
|
|
|
user, _ := user.Current()
|
2015-04-08 08:43:55 -05:00
|
|
|
|
2015-04-09 03:26:26 -05: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 08:43:55 -05:00
|
|
|
|
2015-04-09 03:26:26 -05:00
|
|
|
os.Setenv("DDDXXX", "/tmp")
|
2015-04-08 08:43:55 -05:00
|
|
|
|
2015-04-09 03:26:26 -05: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 08:43:55 -05:00
|
|
|
}
|