-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathat_windows_test.go
58 lines (53 loc) · 1.43 KB
/
at_windows_test.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package windows_test
import (
"internal/syscall/windows"
"os"
"path/filepath"
"syscall"
"testing"
)
func TestOpen(t *testing.T) {
t.Parallel()
dir := t.TempDir()
file := filepath.Join(dir, "a")
f, err := os.Create(file)
if err != nil {
t.Fatal(err)
}
f.Close()
tests := []struct {
path string
flag int
err error
}{
{dir, syscall.O_RDONLY, nil},
{dir, syscall.O_CREAT, nil},
{dir, syscall.O_RDONLY | syscall.O_CREAT, nil},
{file, syscall.O_APPEND | syscall.O_WRONLY | os.O_CREATE, nil},
{file, syscall.O_APPEND | syscall.O_WRONLY | os.O_CREATE | os.O_TRUNC, nil},
{dir, syscall.O_RDONLY | syscall.O_TRUNC, syscall.ERROR_ACCESS_DENIED},
{dir, syscall.O_WRONLY | syscall.O_RDWR, nil}, // TODO: syscall.Open returns EISDIR here, we should reconcile this
{dir, syscall.O_WRONLY, syscall.EISDIR},
{dir, syscall.O_RDWR, syscall.EISDIR},
}
for i, tt := range tests {
dir := filepath.Dir(tt.path)
dirfd, err := syscall.Open(dir, syscall.O_RDONLY, 0)
if err != nil {
t.Error(err)
continue
}
base := filepath.Base(tt.path)
h, err := windows.Openat(dirfd, base, uint64(tt.flag), 0o660)
syscall.CloseHandle(dirfd)
if err == nil {
syscall.CloseHandle(h)
}
if err != tt.err {
t.Errorf("%d: Open got %q, want %q", i, err, tt.err)
}
}
}