go-pulse/cmd/utils/customflags_test.go

29 lines
509 B
Go
Raw Normal View History

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