test

package
v0.0.0-...-0269efd Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDummyToken

func GenerateDummyToken() string

func NoJitter

func NoJitter(d time.Duration) time.Duration

NoJitter replaces test.AddJitter in unit tests, to provide deterministic behavior.

Types

type PolicyEnforcer

type PolicyEnforcer struct {
	// flags by scope
	AllowCluster bool
	AllowDomain  bool
	AllowProject bool
	// flags by action
	AllowView         bool
	AllowEdit         bool
	AllowEditMaxQuota bool
	AllowUncommit     bool
	// match by request attribute
	RejectServiceType string
}

PolicyEnforcer is a gopherpolicy.Enforcer implementation for API tests.

func (*PolicyEnforcer) Enforce

func (e *PolicyEnforcer) Enforce(rule string, ctx policy.Context) bool

Enforce implements the gopherpolicy.Enforcer interface.

type Setup

type Setup struct {
	// fields that are always set
	Ctx            context.Context //nolint:containedctx // only used in tests
	DB             *gorp.DbMap
	Cluster        *core.Cluster
	Clock          *mock.Clock
	Registry       *prometheus.Registry
	TokenValidator *mock.Validator[*PolicyEnforcer]
	// fields that are only set if their respective SetupOptions are given
	Handler http.Handler
}

Setup contains all the pieces that are needed for most tests.

func NewSetup

func NewSetup(t *testing.T, opts ...SetupOption) Setup

NewSetup prepares most or all pieces of Keppel for a test.

func (*Setup) AddCapacityPlugin

func (s *Setup) AddCapacityPlugin(t *testing.T, configYAML string) core.CapacityPlugin

AddCapacityPlugin extends the Setup with a new CapacityPlugin in the middle of a testcase. The `configYAML` must contain a CapacitorConfiguration.

TODO Try to remove this once unit tests have been sufficiently modularized to not require this kind of messing with the setup during the test. TODO Alternatively, reduce code duplication with core.NewCluster().

type SetupOption

type SetupOption func(*setupParams)

SetupOption is an option that can be given to NewSetup().

func WithAPIHandler

func WithAPIHandler(apiBuilder func(*core.Cluster, *gorp.DbMap, gopherpolicy.Validator, func() time.Time, func() string) httpapi.API, middlewares ...httpapi.API) SetupOption

WithAPIHandler is a SetupOption that initializes a http.Handler with the Limes API. The `apiBuilder` function signature matches NewV1API(). We cannot directly call this function because that would create an import cycle, so it must be given by the caller here.

func WithConfig

func WithConfig(yamlStr string) SetupOption

WithConfig is a SetupOption that initializes the test cluster from a configuration provided as YAML. This option is effectively required, as an empty cluster configuration is not allowed.

func WithDBFixtureFile

func WithDBFixtureFile(file string) SetupOption

WithDBFixtureFile is a SetupOption that prefills the test DB by executing the SQL statements in the given file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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