util/os_windows_test.go

48 lines
1.0 KiB
Go
Raw Normal View History

//go:build windows
// +build windows
package util
import (
"errors"
"testing"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/sys/windows"
)
func TestIsSuperUser_SidAllocationError(t *testing.T) {
Convey("IsSuperUser should return false when SID allocation fails", t, func() {
origAllocate := allocateAndInitializeSid
origFatalf := fatalf
defer func() {
allocateAndInitializeSid = origAllocate
fatalf = origFatalf
}()
allocateAndInitializeSid = func(
authority *windows.SidIdentifierAuthority,
subAuthorityCount byte,
subAuthority0 uint32,
subAuthority1 uint32,
subAuthority2 uint32,
subAuthority3 uint32,
subAuthority4 uint32,
subAuthority5 uint32,
subAuthority6 uint32,
subAuthority7 uint32,
sid **windows.SID,
) error {
return errors.New("forced sid allocation error")
}
fatalCalled := false
fatalf = func(format string, v ...interface{}) {
fatalCalled = true
}
So(IsSuperUser(), ShouldBeFalse)
So(fatalCalled, ShouldBeTrue)
})
}