MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestCanonicalPath_NestedSymlink

Function TestCanonicalPath_NestedSymlink

internal/pathutil/path_test.go:89–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestCanonicalPath_NestedSymlink(t *testing.T) {
90 realDir := t.TempDir()
91 realFile := filepath.Join(realDir, "file.txt")
92 if err := os.WriteFile(realFile, []byte("hello"), 0o644); err != nil {
93 t.Fatalf("write file: %v", err)
94 }
95
96 linkDir := t.TempDir()
97 link1 := filepath.Join(linkDir, "link1")
98 if err := os.Symlink(realDir, link1); err != nil {
99 t.Skipf("symlink not supported: %v", err)
100 }
101 link2 := filepath.Join(linkDir, "link2")
102 if err := os.Symlink(link1, link2); err != nil {
103 t.Skipf("nested symlink not supported: %v", err)
104 }
105
106 got, err := CanonicalPath(filepath.Join(link2, "file.txt"))
107 if err != nil {
108 t.Fatalf("CanonicalPath: %v", err)
109 }
110 want, _ := filepath.EvalSymlinks(realFile)
111 if got != want {
112 t.Errorf("CanonicalPath through nested symlinks = %q, want %q", got, want)
113 }
114}
115
116func TestWithinBase_AdditionalCases(t *testing.T) {
117 cases := []struct {

Callers

nothing calls this directly

Calls 1

CanonicalPathFunction · 0.85

Tested by

no test coverage detected