File: fs_test.go

package info (click to toggle)
golang-github-microsoft-go-winio 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (42 lines) | stat: -rw-r--r-- 889 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:build windows

package fs

import (
	"os"
	"path/filepath"
	"strings"
	"testing"

	"golang.org/x/sys/windows"
)

func Test_GetFinalPathNameByHandle(t *testing.T) {
	d := t.TempDir()
	// open f via a relative path
	name := t.Name() + ".txt"
	fullPath := filepath.Join(d, name)

	w, err := os.Getwd()
	if err != nil {
		t.Fatalf("could not get working directory: %v", err)
	}
	if err := os.Chdir(d); err != nil {
		t.Fatalf("could not chdir to %s: %v", d, err)
	}
	defer os.Chdir(w) //nolint:errcheck

	f, err := os.Create(name)
	if err != nil {
		t.Fatalf("could not open %s: %v", fullPath, err)
	}
	defer f.Close()

	path, err := GetFinalPathNameByHandle(windows.Handle(f.Fd()), GetFinalPathDefaultFlag)
	if err != nil {
		t.Fatalf("could not get final path for %s: %v", fullPath, err)
	}
	if strings.EqualFold(fullPath, path) {
		t.Fatalf("expected %s, got %s", fullPath, path)
	}
}