policytest

package
v1.90.8 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package policytest contains test helpers for the syspolicy packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config map[pkey.Key]any

Config is a policyclient.Client implementation with a static mapping of values.

It is used for testing purposes to simulate policy client behavior.

It panics if a value is Set with one type and then accessed with a different expected type and/or value. Some accessors such as GetPreferenceOption and GetVisibility support either a ptype.PreferenceOption/ptype.Visibility in the map, or the string representation as supported by their UnmarshalText methods.

The map value may be an error to return that error value from the accessor.

func (*Config) EnableRegisterChangeCallback

func (c *Config) EnableRegisterChangeCallback()

EnableRegisterChangeCallback makes c support the RegisterChangeCallback for testing. Without calling this, the RegisterChangeCallback does nothing. For watchers to be notified, use the Config.Set method. Changing the map directly obviously wouldn't work.

func (Config) GetBoolean

func (c Config) GetBoolean(key pkey.Key, defaultVal bool) (bool, error)

func (Config) GetDuration

func (c Config) GetDuration(key pkey.Key, defaultVal time.Duration) (time.Duration, error)

func (Config) GetPreferenceOption

func (c Config) GetPreferenceOption(key pkey.Key, defaultVal ptype.PreferenceOption) (ptype.PreferenceOption, error)

func (Config) GetString

func (c Config) GetString(key pkey.Key, defaultVal string) (string, error)

func (Config) GetStringArray

func (c Config) GetStringArray(key pkey.Key, defaultVal []string) ([]string, error)

func (Config) GetUint64

func (c Config) GetUint64(key pkey.Key, defaultVal uint64) (uint64, error)

func (Config) GetVisibility

func (c Config) GetVisibility(key pkey.Key) (ptype.Visibility, error)

func (Config) HasAnyOf

func (c Config) HasAnyOf(keys ...pkey.Key) (bool, error)

func (Config) RegisterChangeCallback

func (c Config) RegisterChangeCallback(callback func(policyclient.PolicyChange)) (func(), error)

func (*Config) Set

func (c *Config) Set(key pkey.Key, value any)

Set sets key to value. The value should be of the correct type that it will be read as later. For PreferenceOption and Visibility, you may also set them to 'string' values and they'll be UnmarshalText'ed into their correct value at Get time.

As a special case, the value can also be of type error to make the accessors return that error value.

func (Config) SetDebugLoggingEnabled

func (sp Config) SetDebugLoggingEnabled(enabled bool)

func (*Config) SetMultiple

func (c *Config) SetMultiple(o Config)

SetMultiple is a batch version of Config.Set. It copies the contents of o into c and does at most one notification wake-up for the whole batch.

Jump to

Keyboard shortcuts

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