...
1
2
3 package fs
4
5 import (
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10
11 "golang.org/x/sys/windows"
12 )
13
14 func Test_GetFinalPathNameByHandle(t *testing.T) {
15 d := t.TempDir()
16
17 name := t.Name() + ".txt"
18 fullPath := filepath.Join(d, name)
19
20 w, err := os.Getwd()
21 if err != nil {
22 t.Fatalf("could not get working directory: %v", err)
23 }
24 if err := os.Chdir(d); err != nil {
25 t.Fatalf("could not chdir to %s: %v", d, err)
26 }
27 defer os.Chdir(w)
28
29 f, err := os.Create(name)
30 if err != nil {
31 t.Fatalf("could not open %s: %v", fullPath, err)
32 }
33 defer f.Close()
34
35 path, err := GetFinalPathNameByHandle(windows.Handle(f.Fd()), GetFinalPathDefaultFlag)
36 if err != nil {
37 t.Fatalf("could not get final path for %s: %v", fullPath, err)
38 }
39 if strings.EqualFold(fullPath, path) {
40 t.Fatalf("expected %s, got %s", fullPath, path)
41 }
42 }
43
View as plain text