mirror of
https://github.com/golang/go
synced 2024-11-22 22:20:03 -07:00
os: mark the share created by TestNetworkSymbolicLink as temporary
Also use a unique share name for each run of the test. This may help with #61467, but since I couldn't reproduce the failure in the first place I don't know. It passes locally for me. For #61467. Change-Id: Ie51e3cf381063e02e4849af5c1a1ed7441ce21c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/512075 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
a3a9b1049e
commit
6f597a8a93
@ -333,7 +333,11 @@ const MB_ERR_INVALID_CHARS = 8
|
||||
//sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
|
||||
//sys GetCurrentThread() (pseudoHandle syscall.Handle, err error) = kernel32.GetCurrentThread
|
||||
|
||||
const STYPE_DISKTREE = 0x00
|
||||
// Constants from lmshare.h
|
||||
const (
|
||||
STYPE_DISKTREE = 0x00
|
||||
STYPE_TEMPORARY = 0x40000000
|
||||
)
|
||||
|
||||
type SHARE_INFO_2 struct {
|
||||
Netname *uint16
|
||||
|
@ -435,7 +435,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
chdir(t, dir)
|
||||
|
||||
shareName := "GoSymbolicLinkTestShare" // hope no conflictions
|
||||
pid := os.Getpid()
|
||||
shareName := fmt.Sprintf("GoSymbolicLinkTestShare%d", pid)
|
||||
sharePath := filepath.Join(dir, shareName)
|
||||
testDir := "TestDir"
|
||||
|
||||
@ -453,11 +454,22 @@ func TestNetworkSymbolicLink(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Per https://learn.microsoft.com/en-us/windows/win32/api/lmshare/ns-lmshare-share_info_2:
|
||||
//
|
||||
// “[The shi2_permissions field] indicates the shared resource's permissions
|
||||
// for servers running with share-level security. A server running user-level
|
||||
// security ignores this member.
|
||||
// …
|
||||
// Note that Windows does not support share-level security.”
|
||||
//
|
||||
// So it shouldn't matter what permissions we set here.
|
||||
const permissions = 0
|
||||
|
||||
p := windows.SHARE_INFO_2{
|
||||
Netname: wShareName,
|
||||
Type: windows.STYPE_DISKTREE,
|
||||
Type: windows.STYPE_DISKTREE | windows.STYPE_TEMPORARY,
|
||||
Remark: nil,
|
||||
Permissions: 0,
|
||||
Permissions: permissions,
|
||||
MaxUses: 1,
|
||||
CurrentUses: 0,
|
||||
Path: wSharePath,
|
||||
@ -466,11 +478,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
|
||||
|
||||
err = windows.NetShareAdd(nil, 2, (*byte)(unsafe.Pointer(&p)), nil)
|
||||
if err != nil {
|
||||
if err == syscall.ERROR_ACCESS_DENIED {
|
||||
t.Skip("you don't have enough privileges to add network share")
|
||||
}
|
||||
if err == _NERR_ServerNotStarted {
|
||||
t.Skip(_NERR_ServerNotStarted.Error())
|
||||
if err == syscall.ERROR_ACCESS_DENIED || err == _NERR_ServerNotStarted {
|
||||
t.Skipf("skipping: NetShareAdd: %v", err)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -509,7 +518,7 @@ func TestNetworkSymbolicLink(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != target {
|
||||
t.Errorf(`os.Readlink("%s"): got %v, want %v`, link, got, target)
|
||||
t.Errorf(`os.Readlink(%#q): got %v, want %v`, link, got, target)
|
||||
}
|
||||
|
||||
got, err = filepath.EvalSymlinks(link)
|
||||
@ -517,7 +526,7 @@ func TestNetworkSymbolicLink(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != target {
|
||||
t.Errorf(`filepath.EvalSymlinks("%s"): got %v, want %v`, link, got, target)
|
||||
t.Errorf(`filepath.EvalSymlinks(%#q): got %v, want %v`, link, got, target)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user