customflags_test.go 509 Bytes
Newer Older
1 2 3
package utils

import (
4 5 6
	"os"
	"os/user"
	"testing"
7 8 9 10
)

func TestPathExpansion(t *testing.T) {

11
	user, _ := user.Current()
12

13 14 15 16 17 18
	tests := map[string]string{
		"/home/someuser/tmp": "/home/someuser/tmp",
		"~/tmp":              user.HomeDir + "/tmp",
		"$DDDXXX/a/b":        "/tmp/a/b",
		"/a/b/":              "/a/b",
	}
19

20
	os.Setenv("DDDXXX", "/tmp")
21

22 23 24 25 26 27
	for test, expected := range tests {
		got := expandPath(test)
		if got != expected {
			t.Errorf("test %s, got %s, expected %s\n", test, got, expected)
		}
	}
28
}