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

Function TestCanonicalPath_RelativePath

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

CanonicalPathFunction · 0.85

Tested by

no test coverage detected