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

Function TestFileIdentityMismatch

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

Source from the content-addressed store, hash-verified

32}
33
34func TestFileIdentityMismatch(t *testing.T) {
35 rootDir := t.TempDir()
36 require.NoError(t, os.WriteFile(filepath.Join(rootDir, "expected"), []byte("expected"), 0o644))
37 require.NoError(t, os.WriteFile(filepath.Join(rootDir, "other"), []byte("other"), 0o644))
38
39 root, err := OpenRoot(rootDir)
40 require.NoError(t, err)
41 defer root.Close()
42 defaultOpenFile := root.openFile
43 root.openFile = func(parent *os.Root, name string, flag int, perm os.FileMode) (*os.File, error) {
44 if name == "expected" {
45 return defaultOpenFile(parent, "other", flag, perm)
46 }
47 return defaultOpenFile(parent, name, flag, perm)
48 }
49
50 file, err := root.Create("expected", 0o644, 0o755, true)
51 assert.Nil(t, file)
52 require.ErrorContains(t, err, "changed while opening")
53 content, err := os.ReadFile(filepath.Join(rootDir, "other"))
54 require.NoError(t, err)
55 assert.Equal(t, "other", string(content))
56}
57
58func TestRedirectTargetClassificationError(t *testing.T) {
59 rootDir := t.TempDir()

Callers

nothing calls this directly

Calls 6

OpenRootFunction · 0.85
WriteFileMethod · 0.80
JoinMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected