plugintestutils

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Any = anyType{}

Any is a placeholder value for any value that can be used in assertions for method calls for a value that can be ignored.

Functions

func CompareTags

func CompareTags(
	t assert.TestingT,
	expectedTags, actualTags []*core.MappingNode,
	tagFieldNames *TagFieldNames,
)

CompareTags compares two slices of tag MappingNodes in an order-independent way. It extracts key-value pairs represented as an object with attributes holding a key and a value that are both expected to be strings.

If nil is passed for tagFieldNames, it defaults to using "key" and "value" as the field names.

func NewTestLinkContext

func NewTestLinkContext(
	providerConfigMap map[string]map[string]*core.ScalarValue,
	contextVariables map[string]*core.ScalarValue,
) provider.LinkContext

NewTestLinkContext creates a provider.LinkContext for testing purposes.

func NewTestProviderContext

func NewTestProviderContext(
	providerName string,
	providerConfig map[string]*core.ScalarValue,
	contextVariables map[string]*core.ScalarValue,
) provider.Context

NewTestProviderContext creates a provider.Context for tests.

func RunLinkChangeStagingTestCases

func RunLinkChangeStagingTestCases[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
](
	testCases []LinkChangeStagingTestCase[
		ResourceAServiceConfig,
		ResourceAService,
		ResourceBServiceConfig,
		ResourceBService,
	],
	createLink func(
		linkServiceDeps pluginutils.LinkServiceDeps[
			ResourceAServiceConfig,
			ResourceAService,
			ResourceBServiceConfig,
			ResourceBService,
		],
	) provider.Link,
	testSuite *suite.Suite,
)

func RunLinkProduceContributionsTestCases added in v0.17.0

func RunLinkProduceContributionsTestCases[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
](
	testCases []LinkProduceContributionsTestCase[
		ResourceAServiceConfig,
		ResourceAService,
		ResourceBServiceConfig,
		ResourceBService,
	],
	createLink func(
		linkServiceDeps pluginutils.LinkServiceDeps[
			ResourceAServiceConfig,
			ResourceAService,
			ResourceBServiceConfig,
			ResourceBService,
		],
	) provider.Link,
	testSuite *suite.Suite,
)

RunLinkProduceContributionsTestCases runs a set of test cases for the `ProduceResourceContributions` method of a link implementation in a provider plugin.

func RunLinkUpdateIntermediaryResourcesTestCases

func RunLinkUpdateIntermediaryResourcesTestCases[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
](
	testCases []LinkUpdateIntermediaryResourcesTestCase[
		ResourceAServiceConfig,
		ResourceAService,
		ResourceBServiceConfig,
		ResourceBService,
	],
	createLink func(
		linkServiceDeps pluginutils.LinkServiceDeps[
			ResourceAServiceConfig,
			ResourceAService,
			ResourceBServiceConfig,
			ResourceBService,
		],
	) provider.Link,
	testSuite *suite.Suite,
)

RunLinkUpdateIntermediaryResourcesTestCases runs a set of test cases for the `UpdateIntermediaryResources“ methods of a link implementation in a provider plugin.

func RunLinkUpdateResourceTestCases

func RunLinkUpdateResourceTestCases[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
](
	testCases []LinkUpdateResourceTestCase[
		ResourceAServiceConfig,
		ResourceAService,
		ResourceBServiceConfig,
		ResourceBService,
	],
	createLink func(
		linkServiceDeps pluginutils.LinkServiceDeps[
			ResourceAServiceConfig,
			ResourceAService,
			ResourceBServiceConfig,
			ResourceBService,
		],
	) provider.Link,
	testSuite *suite.Suite,
)

RunLinkUpdateResourceTestCases runs a set of test cases for the `UpdateLinkedResources` methods of a link implementation in a provider plugin.

func RunResourceDeployTestCases

func RunResourceDeployTestCases[ServiceConfig any, Service any](
	testCases []ResourceDeployTestCase[ServiceConfig, Service],
	createResource func(
		serviceFactory pluginutils.ServiceFactory[ServiceConfig, Service],
		configStore pluginutils.ServiceConfigStore[ServiceConfig],
	) provider.Resource,
	testSuite *suite.Suite,
)

RunResourceDeployTestCases runs a set of test cases for the `Deploy` method of a resource implementation in a provider plugin.

func RunResourceDestroyTestCases

func RunResourceDestroyTestCases[ServiceConfig any, Service any](
	testCases []ResourceDestroyTestCase[ServiceConfig, Service],
	createResource func(
		serviceFactory pluginutils.ServiceFactory[ServiceConfig, Service],
		configStore pluginutils.ServiceConfigStore[ServiceConfig],
	) provider.Resource,
	testSuite *suite.Suite,
)

RunResourceDestroyTestCases runs a set of test cases for the `Destroy` method of a resource implementation in a provider plugin.

func RunResourceGetExternalStateTestCases

func RunResourceGetExternalStateTestCases[ServiceConfig any, Service any](
	testCases []ResourceGetExternalStateTestCase[ServiceConfig, Service],
	createResource func(
		serviceFactory pluginutils.ServiceFactory[ServiceConfig, Service],
		configStore pluginutils.ServiceConfigStore[ServiceConfig],
	) provider.Resource,
	testSuite *suite.Suite,
)

RunResourceGetExternalStateTestCases runs a set of test cases for the `GetExternalState` method of a resource implementation in a provider plugin.

func RunResourceHasStabilisedTestCases

func RunResourceHasStabilisedTestCases[ServiceConfig any, Service any](
	testCases []ResourceHasStabilisedTestCase[ServiceConfig, Service],
	createResource func(
		serviceFactory pluginutils.ServiceFactory[ServiceConfig, Service],
		configStore pluginutils.ServiceConfigStore[ServiceConfig],
	) provider.Resource,
	testSuite *suite.Suite,
)

RunResourceHasStabilisedTestCases runs a set of test cases for the `HasStabilised` method of a resource implementation in a provider plugin.

Types

type EqualityCheckValues

type EqualityCheckValues struct {
	Expected any
	Actual   any
}

EqualityCheckValues is a struct used to hold expected and actual values for equality checks in assertions used with an `equality` matcher that takes an arg and transforms ito to be a value that can be compared with an expected value.

type LinkChangeStagingTestCase

type LinkChangeStagingTestCase[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
] struct {
	// The name of the test case used for errors and debugging.
	Name string
	// ServiceFactoryA is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the first resource (resource A).
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactoryA pluginutils.ServiceFactory[ResourceAServiceConfig, ResourceAService]
	// ServiceFactoryB is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the second resource (resource B).
	//
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for
	// AWS services and the `Service` type parameter could be a `lambda.Service`
	// interface that implements API methods for the AWS Lambda service.
	ServiceFactoryB pluginutils.ServiceFactory[ResourceBServiceConfig, ResourceBService]
	// ConfigStoreA is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the first resource (resource A).
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if your service factory requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStoreA pluginutils.ServiceConfigStore[ResourceAServiceConfig]
	// ConfigStoreB is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the second resource (resource B).
	ConfigStoreB pluginutils.ServiceConfigStore[ResourceBServiceConfig]
	// Input for the link stage changing operation.
	Input *provider.LinkStageChangesInput
	// Expected output from the link stage changing operation.
	ExpectedOutput *provider.LinkStageChangesOutput
	// If true, the test case expects an error to be returned.
	ExpectError bool
	// The expected error message if an error is expected.
	// This doesn't have to be an exact match, the error message
	// just needs to contain the provided string.
	ExpectedErrorMessage string
}

LinkChangeStagingTestCase defines a test case for link change staging.

type LinkProduceContributionsTestCase added in v0.17.0

type LinkProduceContributionsTestCase[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
] struct {
	// The name of the test case used for errors and debugging.
	Name string
	// ServiceFactoryA is a function that creates an instance of the service
	// for the first resource (resource A).
	ServiceFactoryA pluginutils.ServiceFactory[ResourceAServiceConfig, ResourceAService]
	// ServiceFactoryB is a function that creates an instance of the service
	// for the second resource (resource B).
	ServiceFactoryB pluginutils.ServiceFactory[ResourceBServiceConfig, ResourceBService]
	// ConfigStoreA is a store that generates service-specific configuration
	// for the service factory for the first resource (resource A).
	ConfigStoreA pluginutils.ServiceConfigStore[ResourceAServiceConfig]
	// ConfigStoreB is a store that generates service-specific configuration
	// for the service factory for the second resource (resource B).
	ConfigStoreB pluginutils.ServiceConfigStore[ResourceBServiceConfig]
	// CurrentServiceMockCalls is a mock calls tracker embedded into a mock
	// implementation of the service interface.
	//
	// This is optional and only needs to be set if the test case
	// uses mocks instead of a real service.
	CurrentServiceMockCalls *MockCalls
	// Input for producing the link's contributions.
	Input *provider.LinkProduceResourceContributionsInput
	// Expected output from producing the link's contributions.
	ExpectedOutput *provider.LinkProduceResourceContributionsOutput
	// ExpectedOutputMatcher is a function that takes the actual output from the
	// `ProduceResourceContributions` method and returns a prepared actual value along
	// with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.LinkProduceResourceContributionsOutput,
	) (EqualityCheckValues, error)
	// ExtraAssertions is an optional function that is called after the output of
	// the operation successfully matches the expected output or matcher.
	ExtraAssertions func(
		ctx context.Context,
		suite *suite.Suite,
		output *provider.LinkProduceResourceContributionsOutput,
	)
	// ActionsCalled is a mapping of method name to the expected second argument for the
	// method, for a link that reaches a service while producing its contributions.
	//
	// A link that only computes what it needs a resource's spec to say reaches no
	// service, and leaving this empty alongside ActionsNotCalled is how a test says so.
	ActionsCalled map[string]any
	// ActionsNotCalled is a list of method names that are not expected to be called.
	ActionsNotCalled []string
	// If true, the test case expects an error to be returned.
	ExpectError bool
	// The expected error message if an error is expected.
	// This doesn't have to be an exact match, the error message
	// just needs to contain the provided string.
	ExpectedErrorMessage string
}

LinkProduceContributionsTestCase defines a test case for producing the contributions a link makes to the blueprint-declared resources it writes.

Producing contributions is not always a pure computation. A link may read live state to decide what to contribute, or create a resource it owns because the identity of that resource is part of a value it contributes, so the service factories and mock call assertions are the same as those for updating linked resources.

type LinkUpdateIntermediaryResourcesTestCase

type LinkUpdateIntermediaryResourcesTestCase[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
] struct {
	// The name of the test case used for errors and debugging.
	Name string
	// ServiceFactoryA is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the first resource (resource A).
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactoryA pluginutils.ServiceFactory[ResourceAServiceConfig, ResourceAService]
	// ServiceFactoryB is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the second resource (resource B).
	//
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for
	// AWS services and the `Service` type parameter could be a `lambda.Service`
	// interface that implements API methods for the AWS Lambda service.
	ServiceFactoryB pluginutils.ServiceFactory[ResourceBServiceConfig, ResourceBService]
	// ConfigStoreA is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the first resource (resource A).
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if the service factory for resource A requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStoreA pluginutils.ServiceConfigStore[ResourceAServiceConfig]
	// ConfigStoreB is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the second resource (resource B).
	// This is only needed if the service factory for resource B requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStoreB pluginutils.ServiceConfigStore[ResourceBServiceConfig]
	// IntermediariesServiceMockCalls is a mock calls tracker that is expected to be embedded
	// into a mock implementation of the service interface for carrying out
	// the update operation via the provider service APIs for intermediary resources.
	//
	// This is optional and only needs to be set if the test case
	// uses mocks instead of a real service.
	IntermediariesServiceMockCalls *MockCalls
	// Input for the link intermediary resources update operation.
	Input *provider.LinkUpdateIntermediaryResourcesInput
	// Expected output from the link intermediary resources update operation.
	ExpectedOutput *provider.LinkUpdateIntermediaryResourcesOutput
	// ExpectedOutputMatcher is a function that takes the actual output
	// from the `UpdateIntermediaryResources` method and returns a prepared actual
	// value along with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.LinkUpdateIntermediaryResourcesOutput,
	) (EqualityCheckValues, error)
	// ExtraAssertions is an optional function that is called after the output of
	// the operation successfully matches the expected output or matcher.
	// This is useful for adding additional assertions, such as checking
	// the persisted state of intermediary resources in the upstream service
	// for integration tests.
	ExtraAssertions func(
		ctx context.Context,
		suite *suite.Suite,
		output *provider.LinkUpdateIntermediaryResourcesOutput,
	)
	// UpdateActionsCalled is a mapping of method name to the
	// expected second argument for the method.
	// When the value is a slice of any, it is expected that the method
	// is called multiple times with different arguments in the provided order.
	// This will usually be something like a `*Input` or `*Request` struct
	// that service library functions take after a context argument.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `IntermediariesServiceMockCalls` is set).
	UpdateActionsCalled map[string]any
	// UpdateActionsNotCalled is a list of method names
	// that are not expected to be called as a part
	// of the update operation.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `IntermediariesServiceMockCalls` is set).
	UpdateActionsNotCalled []string
	// If true, the test case expects an error to be returned.
	ExpectError bool
	// The expected error message if an error is expected.
	// This doesn't have to be an exact match, the error message
	// just needs to contain the provided string.
	ExpectedErrorMessage string
	// Cleanup is a function that is called after the test case has run.
	// This is used to clean up intermediary resources that were created for the link test case.
	// This is useful for integration tests with real services where the resource
	// needs to be cleaned up after the test case has run regardless of whether
	// the test case passes or fails.
	Cleanup func(
		ctx context.Context,
		failed bool,
		output *provider.LinkUpdateIntermediaryResourcesOutput,
	) error
}

LinkUpdateIntermediaryResourcesTestCase defines a test case for updating intermediary resources in a link.

type LinkUpdateResourceTestCase

type LinkUpdateResourceTestCase[
	ResourceAServiceConfig any,
	ResourceAService any,
	ResourceBServiceConfig any,
	ResourceBService any,
] struct {
	// The name of the test case used for errors and debugging.
	Name string
	// ServiceFactoryA is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the first resource (resource A).
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactoryA pluginutils.ServiceFactory[ResourceAServiceConfig, ResourceAService]
	// ServiceFactoryB is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context
	// for the second resource (resource B).
	//
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for
	// AWS services and the `Service` type parameter could be a `lambda.Service`
	// interface that implements API methods for the AWS Lambda service.
	ServiceFactoryB pluginutils.ServiceFactory[ResourceBServiceConfig, ResourceBService]
	// ConfigStoreA is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the first resource (resource A).
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if the service factory for resource A requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStoreA pluginutils.ServiceConfigStore[ResourceAServiceConfig]
	// ConfigStoreB is a store that generates service-specific configuration
	// for the service factory to create an instance of the service
	// for the second resource (resource B).
	// This is only needed if the service factory for resource B requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStoreB pluginutils.ServiceConfigStore[ResourceBServiceConfig]
	// CurrentServiceMockCalls is a mock calls tracker that is expected to be embedded
	// into a mock implementation of the service interface for carrying out
	// the update operation via the provider service APIs for the resource
	// under test.
	//
	// This is optional and only needs to be set if the test case
	// uses mocks instead of a real service.
	CurrentServiceMockCalls *MockCalls
	// Input for the link resource update operation.
	Input *provider.LinkUpdateLinkedResourcesInput
	// Expected output from the link resource update operation.
	ExpectedOutput *provider.LinkUpdateLinkedResourcesOutput
	// ExpectedOutputMatcher is a function that takes the actual output
	// from the `UpdateLinkedResources` method and returns a prepared actual
	// value along with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.LinkUpdateLinkedResourcesOutput,
	) (EqualityCheckValues, error)
	// ExtraAssertions is an optional function that is called after the output of
	// the operation successfully matches the expected output or matcher.
	// This is useful for adding additional assertions, such as checking
	// the persisted state of the resource in the upstream service for integration tests.
	ExtraAssertions func(
		ctx context.Context,
		suite *suite.Suite,
		output *provider.LinkUpdateLinkedResourcesOutput,
	)
	// UpdateActionsCalled is a mapping of method name to the
	// expected second argument for the method.
	// When the value is a slice of any, it is expected that the method
	// is called multiple times with different arguments in the provided order.
	// This will usually be something like a `*Input` or `*Request` struct
	// that service library functions take after a context argument.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `CurrentServiceMockCalls` is set).
	UpdateActionsCalled map[string]any
	// UpdateActionsNotCalled is a list of method names
	// that are not expected to be called as a part
	// of the update operation.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `CurrentServiceMockCalls` is set).
	UpdateActionsNotCalled []string
	// If true, the test case expects an error to be returned.
	ExpectError bool
	// The expected error message if an error is expected.
	// This doesn't have to be an exact match, the error message
	// just needs to contain the provided string.
	ExpectedErrorMessage string
	// Cleanup is a function that is called after the test case has run.
	// This is used to clean up resources that were created for the link test case.
	// This is useful for integration tests with real services where the resource
	// needs to be cleaned up after the test case has run regardless of whether
	// the test case passes or fails.
	Cleanup func(ctx context.Context, failed bool, output *provider.LinkUpdateLinkedResourcesOutput) error
}

LinkUpdateResourceTestCase defines a test case for link resource update operations.

type MockCalls

type MockCalls struct {
	// contains filtered or unexported fields
}

MockCalls is a lightweight test helper for tracking calls to methods in a mock implementation of an upstream provider service interface. This can be embedded in a service-specific mock struct to track calls to methods and make assertions on them in tests. This struct is safe for concurrent use when multiple calls are made across goroutines at the same time.

Example:

type MyServiceMock struct {
    MockCalls
    // Other fields specific to the mock service
}

// Other methods specific to the mock service

func (m *MyServiceMock) MyMethod(arg1 string, arg2 int) {
    m.RegisterCall(arg1, arg2)
    // Implementation of the method
}

func (*MockCalls) AssertCalled

func (m *MockCalls) AssertCalled(s *suite.Suite, methodName string)

AssertCalled asserts that a method with the given name was called at least once.

func (*MockCalls) AssertCalledWith

func (m *MockCalls) AssertCalledWith(s *suite.Suite, methodName string, callIndex int, args ...any)

AssertCalledWith asserts that a method with the given name was called with the specific arguments for the provided call index (callNumber - 1).

func (*MockCalls) AssertNotCalled

func (m *MockCalls) AssertNotCalled(s *suite.Suite, methodName string)

AssertNotCalled asserts that a method with the given name was not called. This is useful to ensure that a method was not invoked during a test.

func (*MockCalls) RegisterCall

func (m *MockCalls) RegisterCall(args ...any)

RegisterCall registers a call for the current method with the given arguments.

func (*MockCalls) RegisterNamedCall

func (m *MockCalls) RegisterNamedCall(methodName string, args ...any)

RegisterNamedCall registers a call to a method with the given name.

type ResourceDeployTestCase

type ResourceDeployTestCase[ServiceConfig any, Service any] struct {
	// Name is the name of the test case that will be used when running a test suite.
	Name string
	// ServiceFactory is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context.
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactory pluginutils.ServiceFactory[ServiceConfig, Service]
	// ServiceMockCalls is a mock calls tracker that is expected to be embedded
	// into a mock implementation of the service interface for carrying out
	// the save operation via the provider service APIs.
	//
	// This is optional and only needs to be set if the test case
	// uses mocks instead of a real service.
	ServiceMockCalls *MockCalls
	// ConfigStore is a store that generates service-specific configuration
	// for the service factory to create an instance of the service.
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if your service factory requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStore pluginutils.ServiceConfigStore[ServiceConfig]
	// Input is passed into the `Deploy` method of the resource implementation.
	Input *provider.ResourceDeployInput
	// SaveActionsCalled is a mapping of method name to the
	// expected second argument for the method.
	// When the value is a slice of any, it is expected that the method
	// is called multiple times with different arguments in the provided order.
	// This will usually be something like a `*Input` or `*Request` struct
	// that service library functions take after a context argument.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `ServiceMockCalls` is set).
	SaveActionsCalled map[string]any
	// SaveActionsNotCalled is a list of method names
	// that are not expected to be called as a part
	// of the save operation.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `ServiceMockCalls` is set).
	SaveActionsNotCalled []string
	// ExpectedOutput is the expected output from the `Deploy` method.
	ExpectedOutput *provider.ResourceDeployOutput
	// ExpectedOutputMatcher is a function that takes the actual output
	// from the `Deploy` method and returns a prepared actual
	// value along with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.ResourceDeployOutput,
	) (EqualityCheckValues, error)
	// ExtraAssertions is an optional function that is called after the output of
	// the operation successfully matches the expected output or matcher.
	// This is useful for adding additional assertions, such as checking
	// the persisted state of the resource in the upstream service for integration tests.
	ExtraAssertions func(
		ctx context.Context,
		suite *suite.Suite,
		output *provider.ResourceDeployOutput,
	)
	// ExpectError indicates whether the test case expects an error
	// to be returned from the `Deploy` method.
	ExpectError bool
	// Cleanup is a function that is called after the test case has run.
	// This is used to clean up any resources that were created during the test case.
	// This is useful for integration tests with real services where the resource
	// needs to be cleaned up after the test case has run regardless of whether
	// the test case passes or fails.
	Cleanup func(ctx context.Context, output *provider.ResourceDeployOutput) error
}

ResourceDeployTestCase defines a test case for the `Deploy` method of a resource implementation in a provider plugin. This is used to test both creation and update operations which may be two separate methods depending on the provider plugin implementation.

For resources defined with the `providerv1.ResourceDefinition` helper struct, this test case will be used to test both `Create` and `Update` methods as the `Deploy` method in the helper struct will determine the appropriate action to take based on the deploy input.

type ResourceDestroyTestCase

type ResourceDestroyTestCase[ServiceConfig any, Service any] struct {
	// Name is the name of the test case that will be used when running a test suite.
	Name string
	// ServiceFactory is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context.
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactory pluginutils.ServiceFactory[ServiceConfig, Service]
	// ServiceMockCalls is a mock calls tracker that is expected to be embedded
	// into a mock implementation of the service interface for carrying out
	// the destroy operation via the provider service APIs.
	//
	// This is optional and only needs to be set if the test case
	// uses mocks instead of a real service.
	ServiceMockCalls *MockCalls
	// ConfigStore is a store that generates service-specific configuration
	// for the service factory to create an instance of the service.
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if your service factory requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStore pluginutils.ServiceConfigStore[ServiceConfig]
	// Input is passed into the `Destroy` method of the resource implementation.
	Input *provider.ResourceDestroyInput
	// DestroyActionsCalled is a mapping of method name to the
	// expected second argument for the method.
	// When the value is a slice of any, it is expected that the method
	// is called multiple times with different arguments in the provided order.
	// This will usually be something like a `*Input` or `*Request` struct
	// that service library functions take after a context argument.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `ServiceMockCalls` is set).
	DestroyActionsCalled map[string]any
	// SaveActionsNotCalled is a list of method names
	// that are not expected to be called as a part
	// of the save operation.
	//
	// This should only be set if the case uses mocks instead of a real service
	// (i.e. when `ServiceMockCalls` is set).
	DestroyActionsNotCalled []string
	// ExpectError indicates whether the test case expects an error
	// to be returned from the `Destroy` method.
	ExpectError bool
}

ResourceDestroyTestCase defines a test case for the `Destroy` method of a resource implementation in a provider plugin. This is used to test both creation and update operations which may be two separate methods depending on the provider plugin implementation.

type ResourceGetExternalStateTestCase

type ResourceGetExternalStateTestCase[ServiceConfig any, Service any] struct {
	// Name is the name of the test case that will be used when running a test suite.
	Name string
	// ServiceFactory is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context.
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactory pluginutils.ServiceFactory[ServiceConfig, Service]
	// ConfigStore is a store that generates service-specific configuration
	// for the service factory to create an instance of the service.
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if your service factory requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStore pluginutils.ServiceConfigStore[ServiceConfig]
	// Input is the input passed into the `GetExternalState` method.
	Input *provider.ResourceGetExternalStateInput
	// ExpectedOutput is the expected output from the `GetExternalState` method.
	ExpectedOutput *provider.ResourceGetExternalStateOutput
	// ExpectedOutputMatcher is a function that takes the actual output
	// from the `GetExternalState` method and returns a prepared actual
	// value along with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.ResourceGetExternalStateOutput,
	) (EqualityCheckValues, error)
	// CheckTags should be set to true if the subject resource holds tags
	// as an array of key-value pair objects.
	// The default behaviour is to not check tags.
	CheckTags bool
	// TagsFieldName is the name of the field in the resource spec state
	// that holds the tags as an array of key-value pair objects.
	// This field is used only if CheckTags is `true`.
	// The default value is "tags".
	TagsFieldName string
	// TagObjectFieldNames is used to specify the field names for keys and values
	// for tags in the resource spec state.
	// The default field names are "key" and "value", this will only
	// be used if CheckTags is `true`.
	TagObjectFieldNames *TagFieldNames
	// ExpectError indicates whether the test case expects an error
	// to be returned from the `GetExternalState` method.
	ExpectError bool
}

ResourceGetExternalStateTestCase defines a test case for `GetExternalState` method of a resource implementation in a provider plugin.

type ResourceHasStabilisedTestCase

type ResourceHasStabilisedTestCase[ServiceConfig any, Service any] struct {
	// Name is the name of the test case that will be used when running a test suite.
	Name string
	// ServiceFactory is a function that creates an instance of the service
	// using the provided service-specific configuration and a provider context.
	// serviceConfig can be nil for services that do not take a specific configuration
	// to create client instances.
	//
	// For example the `ServiceConfig` type parameter would be `*aws.Config` for AWS services
	// and the `Service` type parameter could be a `lambda.Service` interface that implements
	// API methods for the AWS Lambda service.
	// The `ServiceConfigStore` type parameter would be an optional store
	ServiceFactory pluginutils.ServiceFactory[ServiceConfig, Service]
	// ConfigStore is a store that generates service-specific configuration
	// for the service factory to create an instance of the service.
	// This could be something like a cache for `*aws.Config` for AWS services
	// based on a session ID.
	// This is only needed if your service factory requires a specific
	// configuration struct to be able to create an instance of the service.
	ConfigStore pluginutils.ServiceConfigStore[ServiceConfig]
	// Input is the input passed into the `HasStabilised` method.
	Input *provider.ResourceHasStabilisedInput
	// ExpectedOutput is the expected output from the `HasStabilised` method.
	ExpectedOutput *provider.ResourceHasStabilisedOutput
	// ExpectedOutputMatcher is a function that takes the actual output
	// from the `HasStabilised` method and returns a prepared actual
	// value along with the expected value to be used in an equality check.
	ExpectedOutputMatcher func(
		actual *provider.ResourceHasStabilisedOutput,
	) (EqualityCheckValues, error)
	// ExpectError indicates whether the test case expects an error
	// to be returned from the `GetExternalState` method.
	ExpectError bool
}

ResourceHasStabilisedTestCase defines a test case for `HasStabilised` method of a resource implementation in a provider plugin.

type TagFieldNames

type TagFieldNames struct {
	KeyFieldName   string
	ValueFieldName string
}

TagFieldNames holds the field names used to extract key and value from tag slice MappingNodes. By default, if empty or the values are not set when passed to CompareTags, it will use "key" and "value" as the field names.

Jump to

Keyboard shortcuts

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