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

Function TestCanonicalPath_RelativePath

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

Source from the content-addressed store, hash-verified

65}
66
67func TestCanonicalPath_RelativePath(t *testing.T) {
68 dir := t.TempDir()
69 file := filepath.Join(dir, "test.txt")
70 if err := os.WriteFile(file, []byte("x"), 0o644); err != nil {
71 t.Fatalf("create file: %v", err)
72 }
73
74 oldWd, err := os.Getwd()
75 if err != nil {
76 t.Fatalf("Getwd: %v", err)
77 }
78 t.Cleanup(func() { _ = os.Chdir(oldWd) })
79 if err := os.Chdir(dir); err != nil {
80 t.Fatalf("Chdir: %v", err)
81 }
82
83 got, err := CanonicalPath("test.txt")
84 if err != nil {
85 t.Fatalf("CanonicalPath: %v", err)
86 }
87 if !filepath.IsAbs(got) {
88 t.Errorf("result should be absolute, got %q", got)
89 }
90}
91
92func TestCanonicalPath_NestedSymlink(t *testing.T) {
93 realDir := t.TempDir()

Callers

nothing calls this directly

Calls 1

CanonicalPathFunction · 0.85

Tested by

no test coverage detected