util/os_windows_test.go

36 lines
728 B
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 TestIsSuperUserSidAllocationError(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)
})
}