| 11 | ) |
| 12 | |
| 13 | func TestDirectoryIdentityMismatch(t *testing.T) { |
| 14 | rootDir := t.TempDir() |
| 15 | require.NoError(t, os.Mkdir(filepath.Join(rootDir, "expected"), 0o755)) |
| 16 | require.NoError(t, os.Mkdir(filepath.Join(rootDir, "other"), 0o755)) |
| 17 | |
| 18 | root, err := OpenRoot(rootDir) |
| 19 | require.NoError(t, err) |
| 20 | defer root.Close() |
| 21 | defaultOpenRoot := root.openRoot |
| 22 | root.openRoot = func(parent *os.Root, name string) (*os.Root, error) { |
| 23 | if name == "expected" { |
| 24 | return defaultOpenRoot(parent, "other") |
| 25 | } |
| 26 | return defaultOpenRoot(parent, name) |
| 27 | } |
| 28 | |
| 29 | child, err := root.Sub("expected", 0o755) |
| 30 | assert.Nil(t, child) |
| 31 | require.ErrorContains(t, err, "changed while opening") |
| 32 | } |
| 33 | |
| 34 | func TestFileIdentityMismatch(t *testing.T) { |
| 35 | rootDir := t.TempDir() |