customflags_test.go 555 B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "testing"
  4. "os"
  5. "os/user"
  6. )
  7. func TestPathExpansion(t *testing.T) {
  8. user, _ := user.Current()
  9. tests := map[string]string {
  10. "/home/someuser/tmp": "/home/someuser/tmp",
  11. "~/tmp": user.HomeDir + "/tmp",
  12. "$DDDXXX/a/b": "/tmp/a/b",
  13. "/a/b/": "/a/b",
  14. }
  15. os.Setenv("DDDXXX", "/tmp")
  16. for test, expected := range tests {
  17. got := expandPath(test)
  18. if got != expected {
  19. t.Errorf("test %s, got %s, expected %s\n", test, got, expected)
  20. }
  21. }
  22. }