github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/utilities/utils/customflags_test.go (about)

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