registry

package
v0.0.0-...-7db3de3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package registry simplifies read/write access to the registry and allows for mocking during tests.

Index

Constants

This section is empty.

Variables

View Source
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 Event

type Event uintptr

Event is a void pointer to a Windows event.

type Key

type Key uintptr

Key is a void pointer to a Windows registry key.

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 NewMock

func NewMock() *Mock

NewMock initializes a mocked registry.

func (*Mock) CloseEvent

func (r *Mock) CloseEvent(ptr Event)

CloseEvent mocks releasing an event.

func (*Mock) CloseKey

func (r *Mock) CloseKey(ptr Key)

CloseKey mocks releasing a key, triggering any associated events.

func (*Mock) HKCUCreateKey

func (r *Mock) HKCUCreateKey(path string) (Key, error)

HKCUCreateKey opens a key in the specified path under the HK_CURRENT_USER registry with write permissions.

func (*Mock) HKCUOpenKey

func (r *Mock) HKCUOpenKey(path string) (Key, error)

HKCUOpenKey mocks opening a key in the specified path under the HK_CURRENT_USER registry.

func (*Mock) ReadValue

func (r *Mock) ReadValue(ptr Key, field string) (value string, err error)

ReadValue returns the value of the specified field in the specified key.

func (*Mock) RegNotifyChangeKeyValue

func (r *Mock) RegNotifyChangeKeyValue(ptr Key) (Event, error)

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

func (r *Mock) RequireNoLeaks(t *testing.T)

RequireNoLeaks is a test helper to ensure we freed all allocations.

func (*Mock) UbuntuProKeyExists

func (r *Mock) UbuntuProKeyExists() bool

UbuntuProKeyExists returns whether the UbuntuPro key exists in the mock registry.

func (*Mock) WaitForSingleObject

func (r *Mock) WaitForSingleObject(handle Event) error

WaitForSingleObject waits until the event is triggered. This is a blocking function.

func (*Mock) WriteValue

func (r *Mock) WriteValue(ptr Key, field, value string, multiString bool) error

WriteValue is used to write a value into the registry.

type Windows

type Windows struct{}

Windows is the Windows registry. Any interaction with it will panic.

func (Windows) CloseEvent

func (Windows) CloseEvent(ev Event)

CloseEvent releases the event.

func (Windows) CloseKey

func (Windows) CloseKey(k Key)

CloseKey releases a key.

func (Windows) HKCUCreateKey

func (Windows) HKCUCreateKey(path string) (Key, error)

HKCUCreateKey creates a key in the specified path under the HK_CURRENT_USER registry with write permissions.

func (Windows) HKCUOpenKey

func (Windows) HKCUOpenKey(path string) (Key, error)

HKCUOpenKey opens a key in the specified path under the HK_CURRENT_USER registry with read permissions.

func (Windows) ReadValue

func (Windows) ReadValue(k Key, field string) (string, error)

ReadValue returns the value of the specified field in the specified key.

func (Windows) RegNotifyChangeKeyValue

func (Windows) RegNotifyChangeKeyValue(k Key) (ev Event, err error)

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

func (Windows) WaitForSingleObject(ev Event) (err error)

WaitForSingleObject waits until the event is triggered. This is a blocking function.

func (Windows) WriteValue

func (Windows) WriteValue(k Key, field, value string, multiLine bool) error

WriteValue writes the value to the specified field in the specified key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL