|
| 1 | +package common |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | +) |
| 8 | + |
| 9 | +func TestExpandPath_NoPath_NoBase(t *testing.T) { |
| 10 | + path, err := ExpandPath("", "", "") |
| 11 | + require.NoError(t, err) |
| 12 | + require.Equal(t, ".", path) |
| 13 | +} |
| 14 | + |
| 15 | +func TestExpandPath_NoPath_RelBase(t *testing.T) { |
| 16 | + path, err := ExpandPath("", "repo", "") |
| 17 | + require.NoError(t, err) |
| 18 | + require.Equal(t, "repo", path) |
| 19 | +} |
| 20 | + |
| 21 | +func TestExpandPath_NoPath_AbsBase(t *testing.T) { |
| 22 | + path, err := ExpandPath("", "/repo", "") |
| 23 | + require.NoError(t, err) |
| 24 | + require.Equal(t, "/repo", path) |
| 25 | +} |
| 26 | + |
| 27 | +func TestExpandtPath_RelPath_NoBase(t *testing.T) { |
| 28 | + path, err := ExpandPath("repo", "", "") |
| 29 | + require.NoError(t, err) |
| 30 | + require.Equal(t, "repo", path) |
| 31 | +} |
| 32 | + |
| 33 | +func TestExpandtPath_RelPath_RelBase(t *testing.T) { |
| 34 | + path, err := ExpandPath("repo", "data", "") |
| 35 | + require.NoError(t, err) |
| 36 | + require.Equal(t, "data/repo", path) |
| 37 | +} |
| 38 | + |
| 39 | +func TestExpandtPath_RelPath_AbsBase(t *testing.T) { |
| 40 | + path, err := ExpandPath("repo", "/data", "") |
| 41 | + require.NoError(t, err) |
| 42 | + require.Equal(t, "/data/repo", path) |
| 43 | +} |
| 44 | + |
| 45 | +func TestExpandtPath_AbsPath_NoBase(t *testing.T) { |
| 46 | + path, err := ExpandPath("/repo", "", "") |
| 47 | + require.NoError(t, err) |
| 48 | + require.Equal(t, "/repo", path) |
| 49 | +} |
| 50 | + |
| 51 | +func TestExpandtPath_AbsPath_RelBase(t *testing.T) { |
| 52 | + path, err := ExpandPath("/repo", "data", "") |
| 53 | + require.NoError(t, err) |
| 54 | + require.Equal(t, "/repo", path) |
| 55 | +} |
| 56 | + |
| 57 | +func TestExpandtPath_AbsPath_AbsBase(t *testing.T) { |
| 58 | + path, err := ExpandPath("/repo", "/data", "") |
| 59 | + require.NoError(t, err) |
| 60 | + require.Equal(t, "/repo", path) |
| 61 | +} |
| 62 | + |
| 63 | +func TestExpandPath_BareTilde_NoHome(t *testing.T) { |
| 64 | + path, err := ExpandPath("~", "", "") |
| 65 | + require.NoError(t, err) |
| 66 | + require.Equal(t, ".", path) |
| 67 | +} |
| 68 | + |
| 69 | +func TestExpandPath_BareTilde_RelHome(t *testing.T) { |
| 70 | + path, err := ExpandPath("~", "", "user") |
| 71 | + require.NoError(t, err) |
| 72 | + require.Equal(t, "user", path) |
| 73 | +} |
| 74 | + |
| 75 | +func TestExpandPath_BareTilde_AbsHome(t *testing.T) { |
| 76 | + path, err := ExpandPath("~", "", "/home/user") |
| 77 | + require.NoError(t, err) |
| 78 | + require.Equal(t, "/home/user", path) |
| 79 | +} |
| 80 | + |
| 81 | +func TestExpandtPath_TildeWithPath_NoHome(t *testing.T) { |
| 82 | + path, err := ExpandPath("~/repo", "", "") |
| 83 | + require.NoError(t, err) |
| 84 | + require.Equal(t, "repo", path) |
| 85 | +} |
| 86 | + |
| 87 | +func TestExpandtPath_TildeWithPath_RelHome(t *testing.T) { |
| 88 | + path, err := ExpandPath("~/repo", "", "user") |
| 89 | + require.NoError(t, err) |
| 90 | + require.Equal(t, "user/repo", path) |
| 91 | +} |
| 92 | + |
| 93 | +func TestExpandtPath_TildeWithPath_AbsHome(t *testing.T) { |
| 94 | + path, err := ExpandPath("~/repo", "", "/home/user") |
| 95 | + require.NoError(t, err) |
| 96 | + require.Equal(t, "/home/user/repo", path) |
| 97 | +} |
| 98 | + |
| 99 | +func TestExpandtPath_ErrorTildeUsernameNotSupported_BareTildeUsername(t *testing.T) { |
| 100 | + path, err := ExpandPath("~username", "", "") |
| 101 | + require.ErrorContains(t, err, "~username syntax is not supported") |
| 102 | + require.Equal(t, "", path) |
| 103 | +} |
| 104 | + |
| 105 | +func TestExpandtPath_ErrorTildeUsernameNotSupported_TildeUsernameWithPath(t *testing.T) { |
| 106 | + path, err := ExpandPath("~username/repo", "", "") |
| 107 | + require.ErrorContains(t, err, "~username syntax is not supported") |
| 108 | + require.Equal(t, "", path) |
| 109 | +} |
0 commit comments