-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutable_windows_test.go
More file actions
44 lines (40 loc) · 1.1 KB
/
Copy pathexecutable_windows_test.go
File metadata and controls
44 lines (40 loc) · 1.1 KB
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
43
44
package verify
import (
"errors"
"os"
"testing"
)
func TestCanonicalWindowsExecutable(t *testing.T) {
executable, err := os.Executable()
if err != nil {
t.Fatal(err)
}
if result, err := canonicalExecutablePlatform(executable); err != nil || result != executable {
t.Fatalf("ordinary executable = (%q, %v)", result, err)
}
failure := errors.New("failure")
if _, err := canonicalWindowsExecutableWith(executable, func(string) (os.FileInfo, error) {
return nil, failure
}, nil, nil); !errors.Is(err, failure) {
t.Fatalf("lstat error = %v", err)
}
information, err := os.Stat(executable)
if err != nil {
t.Fatal(err)
}
symlink := fileInfoWithMode{FileInfo: information, mode: information.Mode() | os.ModeSymlink}
if _, err = canonicalWindowsExecutableWith(executable, func(string) (os.FileInfo, error) {
return symlink, nil
}, func(string) (string, error) {
return "", failure
}, os.Stat); !errors.Is(err, failure) {
t.Fatalf("symlink error = %v", err)
}
}
type fileInfoWithMode struct {
os.FileInfo
mode os.FileMode
}
func (value fileInfoWithMode) Mode() os.FileMode {
return value.mode
}