handlertest

package
v0.0.0-...-c2efb00 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const TargetName = "test.target"

TargetName is the default target name.

Variables

View Source
var (
	ErrNotFound    = errors.New("not found")
	ErrInvalidType = errors.New("invalid type")
)
View Source
var ErrInvalidObject = errors.New("invalid object")

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Namespaces sync.Map
}

Cache is a threadsafe Cache for the test Handler which keeps track of Namespaces.

func (*Cache) Add

func (c *Cache) Add(key []string, object interface{}) error

Add inserts object into Cache if object is a Namespace.

func (*Cache) Remove

func (c *Cache) Remove(key []string)

type Handler

type Handler struct {
	// Name, if set, is the name of the Handler. Otherwise defaults to TargetName.
	Name *string

	// ShouldHandle is whether Handler should handle Object.
	// If unset, handles all Objects.
	ShouldHandle func(*Object) bool

	ForbiddenEnforcement *string

	// ProcessDataError is the error to return when ProcessData is called.
	// If nil returns no error.
	ProcessDataError error

	Cache *Cache
}

func (*Handler) GetCache

func (h *Handler) GetCache() handler.Cache

func (*Handler) GetName

func (h *Handler) GetName() string

func (*Handler) HandleReview

func (h *Handler) HandleReview(obj interface{}) (bool, interface{}, error)

func (*Handler) MatchSchema

func (h *Handler) MatchSchema() apiextensions.JSONSchemaProps

func (*Handler) ProcessData

func (h *Handler) ProcessData(obj interface{}) (bool, []string, interface{}, error)

func (*Handler) ToMatcher

func (h *Handler) ToMatcher(constraint *unstructured.Unstructured) (constraints.Matcher, error)

func (*Handler) ValidateConstraint

func (h *Handler) ValidateConstraint(constraint *unstructured.Unstructured) error

type Matcher

type Matcher struct {
	Namespace string
	Cache     *Cache
}

Matcher is a test matcher which matches Objects with a matching namespace. Checks that Namespace exists in cache before proceeding.

func (Matcher) Match

func (m Matcher) Match(review interface{}) (bool, error)

Match returns true if the object under review's Namespace matches the Namespace the Matcher filters for. If the object's Namespace is not cached in cache, returns an error.

Matches all objects if the Matcher has no namespace specified.

type Object

type Object struct {
	// Name is the identifier of an Object within the scope of its Namespace
	// (if present). If unset, the Object is a special "Namespace" object.
	Name string `json:"name"`

	// Namespace is used for Constraints which apply to a subset of Objects.
	// If unset, the Object is not scoped to a Namespace.
	Namespace string `json:"namespace"`

	// Data is checked by "CheckData" templates.
	Data string `json:"data"`
}

Object is a test object under review. The idea is to represent objects just complex enough to showcase (and test) the features of frameworks's Client, Drivers, and Handlers.

func (Object) Key

func (o Object) Key() []string

type Review

type Review struct {
	Ignored bool   `json:"ignored"`
	Object  Object `json:"object"`
}

Review is the request to review Object.

func NewReview

func NewReview(namespace, name, data string) *Review

Jump to

Keyboard shortcuts

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