Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateDummyToken ¶
func GenerateDummyToken() string
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.
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] Auditor *audittools.MockAuditor // 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 ¶
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, audittools.Auditor, 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.