36 lines
729 B
Go
36 lines
729 B
Go
//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 := allocateAdminGroupSid
|
|
origFatalf := fatalf
|
|
defer func() {
|
|
allocateAdminGroupSid = origAllocate
|
|
fatalf = origFatalf
|
|
}()
|
|
|
|
allocateAdminGroupSid = func(_ **windows.SID) error {
|
|
return errors.New("forced sid allocation error")
|
|
}
|
|
|
|
fatalCalled := false
|
|
fatalf = func(_ string, _ ...interface{}) {
|
|
fatalCalled = true
|
|
}
|
|
|
|
So(IsSuperUser(), ShouldBeFalse)
|
|
So(fatalCalled, ShouldBeTrue)
|
|
})
|
|
}
|