MCPcopy Create free account
hub / github.com/cli/cli / TestDirectoryIdentityMismatch

Function TestDirectoryIdentityMismatch

internal/safepaths/root_validation_test.go:13–32  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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
34func TestFileIdentityMismatch(t *testing.T) {
35 rootDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

OpenRootFunction · 0.85
JoinMethod · 0.80
SubMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected