(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func TestExpandPath(t *testing.T) { |
| 107 | homeDir, err := os.UserHomeDir() |
| 108 | assert.NoError(t, err) |
| 109 | |
| 110 | testCases := []struct { |
| 111 | name string |
| 112 | input string |
| 113 | expected string |
| 114 | hasError bool |
| 115 | }{ |
| 116 | {"Just tilde", "~", homeDir, false}, |
| 117 | {"Tilde with path", "~/documents", filepath.Join(homeDir, "documents"), false}, |
| 118 | {"Absolute path", "/etc/hosts", "/etc/hosts", false}, |
| 119 | {"Relative path", "./test", "./test", false}, |
| 120 | {"Unsupported tilde user", "~user/docs", "", true}, |
| 121 | } |
| 122 | |
| 123 | for _, tc := range testCases { |
| 124 | t.Run(tc.name, func(t *testing.T) { |
| 125 | expanded, err := ExpandPath(tc.input) |
| 126 | if tc.hasError { |
| 127 | assert.Error(t, err) |
| 128 | } else { |
| 129 | assert.NoError(t, err) |
| 130 | assert.Equal(t, tc.expected, expanded) |
| 131 | } |
| 132 | }) |
| 133 | } |
| 134 | } |
nothing calls this directly
no test coverage detected