| 1 |
|
| 2 |
|
| 3 |
package osfs |
| 4 |
|
| 5 |
import ( |
| 6 |
"path/filepath" |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestChrootPathKeepsDriveAbsolutePathFromEmptyBase(t *testing.T) { |
| 13 |
fs := newTestBoundOS(t, "") |
| 14 |
|
| 15 |
want := filepath.Clean(`C:\Users\runner\repo.git`) |
| 16 |
assert.Equal(t, want, fs.chrootPath(`C:\Users\runner\repo.git`)) |
| 17 |
assert.Equal(t, want, fs.chrootPath(`/C:/Users/runner/repo.git`)) |
| 18 |
} |
| 19 |
|
| 20 |
func TestNewBoundOSNormalizesSlashPrefixedDriveBase(t *testing.T) { |
| 21 |
fs := newTestBoundOS(t, `/C:/Users/runner/repo.git`) |
| 22 |
|
| 23 |
assert.Equal(t, filepath.Clean(`C:\Users\runner\repo.git`), fs.Root()) |
| 24 |
} |
| 25 |
|
| 26 |
func TestOperationRootUsesDriveForAbsolutePathFromEmptyBase(t *testing.T) { |
| 27 |
fs := newTestBoundOS(t, "") |
| 28 |
|
| 29 |
assert.Equal(t, `C:\`, fs.operationRoot(`C:\Users\runner\.gitconfig`)) |
| 30 |
assert.Equal(t, `C:\`, fs.operationRoot(`/C:/Users/runner/.gitconfig`)) |
| 31 |
} |
| 32 |
|
| 33 |
func TestSlashPrefixedDrivePathIsCleanedUnderDriveRoot(t *testing.T) { |
| 34 |
assert.Equal(t, filepath.Join("Users", "runner", ".gitconfig"), cleanUnderRoot(`/C:/Users/runner/.gitconfig`)) |
| 35 |
|
| 36 |
rel, ok := relativeInsideBase(`C:\`, `/C:/Users/runner/.gitconfig`) |
| 37 |
assert.True(t, ok) |
| 38 |
assert.Equal(t, filepath.Join("Users", "runner", ".gitconfig"), rel) |
| 39 |
} |