Documentation ¶
Overview ¶
Package testroutines holds a collection of common test procedures. They provide a framework to write mock tests.
Index ¶
- Constants
- func ComparatorPagination(serverURL string, actual *common.ReadResult, expected *common.ReadResult) bool
- func ComparatorSubsetMetadata(_ string, actual, expected *common.ListObjectMetadataResult) bool
- func ComparatorSubsetRead(serverURL string, actual, expected *common.ReadResult) bool
- func ComparatorSubsetWrite(_ string, actual, expected *common.WriteResult) bool
- type Comparator
- type ConnectorBuilder
- type Delete
- type DeleteType
- type Metadata
- type MetadataType
- type Read
- type ReadType
- type TestCase
- type Write
- type WriteType
Constants ¶
const URLTestServer = "{{testServerURL}}"
URLTestServer is an alias to mock server BaseURL. For usage please refer to ComparatorPagination.
Variables ¶
This section is empty.
Functions ¶
func ComparatorPagination ¶
func ComparatorPagination(serverURL string, actual *common.ReadResult, expected *common.ReadResult) bool
ComparatorPagination will check pagination related fields. Note: you may use an alias for Mock-Server-URL which will be dynamically resolved at runtime. Example:
common.ReadResult{ NextPage: testroutines.URLTestServer + "/v3/contacts?cursor=bGltaXQ9MSZuZXh0PTI=" }
At runtime this may look as follows: http://127.0.0.1:38653/v3/contacts?cursor=bGltaXQ9MSZuZXh0PTI=.
func ComparatorSubsetMetadata ¶
func ComparatorSubsetMetadata(_ string, actual, expected *common.ListObjectMetadataResult) bool
ComparatorSubsetMetadata will check a subset of fields is present. Errors could be an exact match for each object or subset can be used as well. This must be done by specifying expected errors using mockutils.ExpectedSubsetErrors. Then errors.Is() will be applied for each error.
For if this is the case refer to the example below:
Errors: map[string]error{ "arsenal": mockutils.ExpectedSubsetErrors{ // Is doing a subset match. common.ErrCaller, errors.New(string(unsupportedResponse)), }, "arsenal": common.NewHTTPStatusError(http.StatusBadRequest, // Is doing exact match. fmt.Errorf("%w: %s", common.ErrCaller, string(unsupportedResponse))), },
func ComparatorSubsetRead ¶
func ComparatorSubsetRead(serverURL string, actual, expected *common.ReadResult) bool
ComparatorSubsetRead ensures that a subset of fields or raw data is present in the response. This is convenient for cases where the returned data is large, allowing for a more concise test that still validates the desired behavior.
func ComparatorSubsetWrite ¶
func ComparatorSubsetWrite(_ string, actual, expected *common.WriteResult) bool
ComparatorSubsetWrite ensures that only the specified metadata objects are present, while other values are verified through an exact match..
Types ¶
type Comparator ¶
Comparator is an equality function with custom rules. This package provides the most commonly used comparators.
type ConnectorBuilder ¶
ConnectorBuilder is a callback method to construct and configure connector for testing. This is a factory method called for every test suite.
type Delete ¶
type Delete DeleteType
Delete is a test suite useful for testing connectors.DeleteConnector interface.
func (Delete) Run ¶
func (d Delete) Run(t *testing.T, builder ConnectorBuilder[connectors.DeleteConnector])
Run provides a procedure to test connectors.DeleteConnector
type DeleteType ¶
type DeleteType = TestCase[common.DeleteParams, *common.DeleteResult]
type Metadata ¶
type Metadata MetadataType
Metadata is a test suite useful for testing connectors.ObjectMetadataConnector interface.
func (Metadata) Run ¶
func (m Metadata) Run(t *testing.T, builder ConnectorBuilder[connectors.ObjectMetadataConnector])
Run provides a procedure to test connectors.ObjectMetadataConnector
type MetadataType ¶
type MetadataType = TestCase[[]string, *common.ListObjectMetadataResult]
type Read ¶
type Read ReadType
Read is a test suite useful for testing connectors.ReadConnector interface.
func (Read) Run ¶
func (r Read) Run(t *testing.T, builder ConnectorBuilder[connectors.ReadConnector])
Run provides a procedure to test connectors.ReadConnector
type ReadType ¶
type ReadType = TestCase[common.ReadParams, *common.ReadResult]
type TestCase ¶
type TestCase[Input any, Output any] struct { // Name of the test suite. Name string // Input passed to the tested method. Input Input // Mock Server which connector will call. Server *httptest.Server // Custom Comparator of how expected output agrees with actual output. Comparator Comparator[Output] // Expected return value. Expected Output // ExpectedErrs is a list of errors that must be present in error output. ExpectedErrs []error }
TestCase describes major components that are used to test any Connector methods. It is universal and generic `Input` data type is what the tested method accepts, while `Output` value represents the data type of the expected output.
type Write ¶
type Write WriteType
Write is a test suite useful for testing connectors.WriteConnector interface.
func (Write) Run ¶
func (w Write) Run(t *testing.T, builder ConnectorBuilder[connectors.WriteConnector])
Run provides a procedure to test connectors.WriteConnector
type WriteType ¶
type WriteType = TestCase[common.WriteParams, *common.WriteResult]