actuatortest

package
v0.14.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAPIListResponse

func AssertAPIListResponse(t *testing.T, resp *http.Response)

AssertAPIListResponse fail the test if the response doesn't contain any "endpoint". This function only support V3 response.

func AssertEnvResponse

func AssertEnvResponse(t *testing.T, resp *http.Response)

AssertEnvResponse fail the test if the response doesn't contain "test" profile. This function only support V3 response.

func AssertHealthResponse

func AssertHealthResponse(t *testing.T, resp *http.Response, expectations ...ExpectedHealthOptions)

AssertHealthResponse fail the test if given response is not a correct "health" endpoint response. By default, this function expect a simple health response with status UP and no details nor components disclosed. This function support both V2 and V3 responses, default to V3

func AssertLoggersResponse

func AssertLoggersResponse(t *testing.T, resp *http.Response, expectations ...ExpectedLoggersOptions)

AssertLoggersResponse fail the test if the response is not the response of "loggers" endpoint. By default, this function expects:

  • The response includes all loggers with effective level and all supported levels.

This function only support V3 response.

func WithEndpoints

func WithEndpoints(opts ...ActuatorOptions) test.Options

WithEndpoints is a convenient group of test options that enables actuator endpoints with following configuration

  • "info", "health" and "env" are initialized
  • The default "tokenauth" authentication is disabled. (sectest package can be used to test securities)
  • Uses the default properties and permission based access control. Custom access control can be registered

Note 1: Choice of web testing environment are configured separately.

See webtest.WithMockedServer() and webtest.WithRealServer()

Note 2: Actuator endpoints usually requires correct properties to be fully functional,

make sure the test have all "management" properties configured correctly.

Note 3: Additional endpoints can be added by directly adding their Modules in test.

Example: test.RunTest(context.Background(), t,

	apptest.Bootstrap(),
	webtest.WithMockedServer(),
	sectest.WithMockedMiddleware(),
	apptest.WithModules(
		// additional endpoints
		loggers.Module,
	),
	apptest.WithBootstrapConfigFS(testdata.MyTestBootstrapFS),
	apptest.WithConfigFS(testdata.MyTestConfigFS),
	apptest.WithProperties("more.properties: value"...),
	test.GomegaSubTest(SubTestAdminEndpoints(), "MyTests"),
)

Types

type ActuatorOption

type ActuatorOption struct {
	// Default to false. When set true, the default health, info and env endpoints are not initialized
	DisableAllEndpoints bool
	// Default to true. When set to false, the default authentication is installed.
	// Depending on the defualt authentication (currently tokenauth), more dependencies might be needed
	DisableDefaultAuthentication bool
}

type ActuatorOptions

type ActuatorOptions func(opt *ActuatorOption)

func DisableAllEndpoints

func DisableAllEndpoints() ActuatorOptions

DisableAllEndpoints is an ActuatorOptions that disable all endpoints in test. Any endpoint need to be installed manually via apptest.WithModules(...)

type ExpectedHealth

type ExpectedHealth struct {
	Status             health.Status
	HasDetails         bool
	HasComponents      bool
	RequiredComponents []string
}

type ExpectedHealthOptions

type ExpectedHealthOptions func(h *ExpectedHealth)

func ExpectHealth

func ExpectHealth(status health.Status) ExpectedHealthOptions

func ExpectHealthComponents

func ExpectHealthComponents(requiredComps ...string) ExpectedHealthOptions

func ExpectHealthDetails

func ExpectHealthDetails() ExpectedHealthOptions

type ExpectedLoggers

type ExpectedLoggers struct {
	Single           bool
	EffectiveLevels  map[string]interface{}
	ConfiguredLevels map[string]interface{}
}

type ExpectedLoggersOptions

type ExpectedLoggersOptions func(l *ExpectedLoggers)

func ExpectLoggersConfiguredLevels

func ExpectLoggersConfiguredLevels(kvs ...string) ExpectedLoggersOptions

func ExpectLoggersEffectiveLevels

func ExpectLoggersEffectiveLevels(kvs ...string) ExpectedLoggersOptions

func ExpectLoggersSingleEntry

func ExpectLoggersSingleEntry(expectedLevels ...interface{}) ExpectedLoggersOptions

ExpectLoggersSingleEntry expects logger response is a single entry. Maximum of two "expected levels" are supported:

  • 1st level is expected "effective level". If nil or missing, it's expected to be any value.
  • 2nd level is expected "configured level". If nil, it's expected to be any value. If missing, it's not checked at all

Note: "effectiveLevel" is expected always available in any "loggers" response.

Jump to

Keyboard shortcuts

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