Documentation ¶
Overview ¶
Package registry simplifies read/write access to the registry and allows for mocking during tests.
Index ¶
- Variables
- type Event
- type Key
- type Mock
- func (r *Mock) CloseEvent(ptr Event)
- func (r *Mock) CloseKey(ptr Key)
- func (r *Mock) HKCUCreateKey(path string) (Key, error)
- func (r *Mock) HKCUOpenKey(path string) (Key, error)
- func (r *Mock) ReadValue(ptr Key, field string) (value string, err error)
- func (r *Mock) RegNotifyChangeKeyValue(ptr Key) (Event, error)
- func (r *Mock) RequireNoLeaks(t *testing.T)
- func (r *Mock) UbuntuProKeyExists() bool
- func (r *Mock) WaitForSingleObject(handle Event) error
- func (r *Mock) WriteValue(ptr Key, field, value string, multiString bool) error
- type Windows
- func (Windows) CloseEvent(ev Event)
- func (Windows) CloseKey(k Key)
- func (Windows) HKCUCreateKey(path string) (Key, error)
- func (Windows) HKCUOpenKey(path string) (Key, error)
- func (Windows) ReadValue(k Key, field string) (string, error)
- func (Windows) RegNotifyChangeKeyValue(k Key) (ev Event, err error)
- func (Windows) WaitForSingleObject(ev Event) (err error)
- func (Windows) WriteValue(k Key, field, value string, multiLine bool) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotExist is returned when attempting to open a key that does not exist. ErrKeyNotExist = errors.New("the key does not exist") // ErrFieldNotExist is returned when attempting to read a key field that does not exist. ErrFieldNotExist = errors.New("the field does not exist") // ErrAccessDenied is printed when an action is blocked by the key's security descriptor. // // It is NOT used when the action is blocked by access rights such READ or WRITE. // In that case we allow the syscall error to bubble up, as we don't need to catch it. ErrAccessDenied = errors.New("access denied") // ErrMock is the error returned when everything went fine but the mock // setup requested an error to be thrown. ErrMock = errors.New("error triggered by mock setup") )
Although the stdlibs' registry and syscall packages return typed errors, these are only defined in their _windows files. We convert the relevant ones here to cross-platform errors.
Functions ¶
This section is empty.
Types ¶
type Mock ¶
type Mock struct { // Settings to break the registry CannotCreate atomic.Bool CannotOpen atomic.Bool CannotRead atomic.Bool CannotWatch atomic.Bool CannotWait atomic.Bool // contains filtered or unexported fields }
Mock is a fake registry stored in memory.
func (*Mock) HKCUCreateKey ¶
HKCUCreateKey opens a key in the specified path under the HK_CURRENT_USER registry with write permissions.
func (*Mock) HKCUOpenKey ¶
HKCUOpenKey mocks opening a key in the specified path under the HK_CURRENT_USER registry.
func (*Mock) RegNotifyChangeKeyValue ¶
RegNotifyChangeKeyValue creates an event and attaches it to a registry key. Modifying that key or its children will trigger the event. This trigger can be detected by WaitForSingleObject.
func (*Mock) RequireNoLeaks ¶
RequireNoLeaks is a test helper to ensure we freed all allocations.
func (*Mock) UbuntuProKeyExists ¶
UbuntuProKeyExists returns whether the UbuntuPro key exists in the mock registry.
func (*Mock) WaitForSingleObject ¶
WaitForSingleObject waits until the event is triggered. This is a blocking function.
type Windows ¶
type Windows struct{}
Windows is the Windows registry. Any interaction with it will panic.
func (Windows) HKCUCreateKey ¶
HKCUCreateKey creates a key in the specified path under the HK_CURRENT_USER registry with write permissions.
func (Windows) HKCUOpenKey ¶
HKCUOpenKey opens a key in the specified path under the HK_CURRENT_USER registry with read permissions.
func (Windows) RegNotifyChangeKeyValue ¶
RegNotifyChangeKeyValue creates an event and attaches it to a registry key. Modifying that key or its children will trigger the event. This trigger can be detected by WaitForSingleObject.
func (Windows) WaitForSingleObject ¶
WaitForSingleObject waits until the event is triggered. This is a blocking function.