tester

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTestFail = errors.New("test failed")

Functions

func NewK8sUserInfo

func NewK8sUserInfo(u UserInfo) user.DefaultInfo

func Run

func Run(cfg CmdConfig, pathList []string) error

Run runs the test cases defined in multiple manifest files.

func RunInit

func RunInit(cfg CmdConfig, targetFilePath string) error

Types

type CmdConfig

type CmdConfig struct {
	Debug   bool
	Verbose bool
}

type GVK

type GVK struct {
	Group   string `yaml:"group,omitempty"`
	Version string `yaml:"version,omitempty"`
	Kind    string `yaml:"kind"`
}

type NameWithGVK

type NameWithGVK struct {
	GVK            `yaml:",inline"`
	NamespacedName `yaml:",inline"`
}

func NewNameWithGVK

func NewNameWithGVK(gvk schema.GroupVersionKind, namespacedName NamespacedName) NameWithGVK

NewNameWithGVK creates NameWithGVK from GVK and NamespacedName.

func NewNameWithGVKFromObj

func NewNameWithGVKFromObj(obj *unstructured.Unstructured) NameWithGVK

NewNameWithGVKFromObj creates NameWithGVK from unstructured object.

func (NameWithGVK) IsValid

func (n NameWithGVK) IsValid() bool

func (NameWithGVK) Match

func (query NameWithGVK) Match(given NameWithGVK) bool

func (NameWithGVK) String

func (n NameWithGVK) String() string

type NamespacedName

type NamespacedName struct {
	Namespace string `yaml:"namespace,omitempty"`
	Name      string `yaml:"name"`
}

func (NamespacedName) IsValid

func (n NamespacedName) IsValid() bool

func (NamespacedName) String

func (n NamespacedName) String() string

type PolicyDecisionExpect

type PolicyDecisionExpect string
const (
	Admit PolicyDecisionExpect = "admit"
	Deny  PolicyDecisionExpect = "deny"
	Error PolicyDecisionExpect = "error"
	Skip  PolicyDecisionExpect = "skip"
)

type ResourceLoader

type ResourceLoader struct {
	Vaps      map[string]*v1.ValidatingAdmissionPolicy
	Resources map[NameWithGVK]*unstructured.Unstructured
}

func NewResourceLoader

func NewResourceLoader() *ResourceLoader

func (*ResourceLoader) GetResource

func (r *ResourceLoader) GetResource(ngvk NameWithGVK) (*unstructured.Unstructured, error)

func (*ResourceLoader) LoadResources

func (r *ResourceLoader) LoadResources(paths []string)

func (*ResourceLoader) LoadVaps

func (r *ResourceLoader) LoadVaps(paths []string)

type TestCase

type TestCase struct {
	Object    NameWithGVK          `yaml:"object,omitempty"`
	OldObject NameWithGVK          `yaml:"oldObject,omitempty"`
	Param     NamespacedName       `yaml:"param,omitempty"`
	Expect    PolicyDecisionExpect `yaml:"expect,omitempty"`
	UserInfo  UserInfo             `yaml:"userInfo,omitempty"`
}

TestCase is a struct to represent a single test case.

type TestManifests

type TestManifests struct {
	ValidatingAdmissionPolicies []string               `yaml:"validatingAdmissionPolicies,omitempty"`
	Resources                   []string               `yaml:"resources,omitempty"`
	TestSuites                  []TestsForSinglePolicy `yaml:"testSuites,omitempty"`
}

TestManifests is a struct to represent the whole test manifest file.

func (TestManifests) IsValid

func (t TestManifests) IsValid() (bool, string)

type TestsForSinglePolicy

type TestsForSinglePolicy struct {
	Policy string     `yaml:"policy"`
	Tests  []TestCase `yaml:"tests"`
}

TestsForSinglePolicy is a struct to aggregate multiple test cases for a single policy.

type UserInfo

type UserInfo struct {
	Name   string   `yaml:"name"`
	Groups []string `yaml:"groups"`
	Extra  map[string][]string
}

UserInfo is a struct to represent user information to populate request.userInfo.

Jump to

Keyboard shortcuts

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