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