cts

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: 9 Imported by: 0

Documentation

Overview

Package cts is a set of methods for constructing ConstraintTemplates for use in tests.

Index

Constants

View Source
const (
	ModuleDeny = `
package foo

violation[{"msg": msg}] {
  true
  msg := "denied"
}
`
	MockTemplateName  string = "fakes"
	MockTemplate      string = "Fakes"
	MockTargetHandler string = "foo"
)

Variables

This section is empty.

Functions

func Code

func Code(engine string, source interface{}) templates.Code

func ExpectedSchema

func ExpectedSchema(pm PropMap) *apiextensions.JSONSchemaProps

func MakeConstraint

func MakeConstraint(t testing.TB, kind, name string, args ...ConstraintArg) *unstructured.Unstructured

MakeConstraint creates a new test Constraint.

func New

func New(opts ...Opt) *templates.ConstraintTemplate

func Prop

Prop constructs an Object schema node with the passed property map.

func PropTyped

func PropTyped(propType string) apiextensions.JSONSchemaProps

PropTyped creates a typed property with no subfields.

func PropUnstructured

func PropUnstructured() apiextensions.JSONSchemaProps

PropUnstructured constructs a schema node with no specified underlying structure.

func Target

func Target(name string, rego string, libs ...string) templates.Target

func TargetCustomEngines

func TargetCustomEngines(name string, codes ...templates.Code) templates.Target

func TargetNoEngine

func TargetNoEngine(name string) templates.Target

Types

type ConstraintArg

type ConstraintArg func(*unstructured.Unstructured) error

func EnforcementAction

func EnforcementAction(action string) ConstraintArg

EnforcementAction sets the action to be taken if the Constraint is violated.

func MatchNamespace

func MatchNamespace(namespace string) ConstraintArg

MatchNamespace modifies the Constraint to only match objects with the passed Namespace.

func Set

func Set(value interface{}, path ...string) ConstraintArg

Set sets an arbitrary value inside the Constraint.

func WantData

func WantData(data string) ConstraintArg

WantData sets the Constraint to verify that data of objects under review is set to wantData. Only meaningful for CheckData constraints.

type Opt

type Opt func(*templates.ConstraintTemplate)

func OptCRDNames

func OptCRDNames(kind string) Opt

func OptCRDSchema

func OptCRDSchema(pm PropMap) Opt

func OptLabels

func OptLabels(labels map[string]string) Opt

func OptName

func OptName(name string) Opt

func OptTargets

func OptTargets(targets ...templates.Target) Opt

Jump to

Keyboard shortcuts

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