testframework

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package testframework provides testing utilities and helpers for the PingOne Go Client SDK. It includes client configuration helpers, environment management utilities, and common test patterns for integration testing with PingOne services.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultEnvironmentDefinition is a function that creates a standard test environment configuration.
	// The name parameter sets the environment name, regionCodeStr specifies the PingOne region,
	// licenseId must be a valid PingOne license UUID, and withBootstrap determines whether to
	// include full DaVinci features or use minimal configuration. This function creates an
	// environment with all standard PingOne services enabled for comprehensive testing.
	DefaultEnvironmentDefinition = func(name, regionCodeStr string, licenseId uuid.UUID, withBootstrap bool) pingone.EnvironmentCreateRequest {

		davinciTags := make([]string, 0)
		if !withBootstrap {
			davinciTags = append(davinciTags, "DAVINCI_MINIMAL")
		}

		regionCode := pingone.EnvironmentRegionCode(regionCodeStr)

		return pingone.EnvironmentCreateRequest{
			BillOfMaterials: &pingone.EnvironmentBillOfMaterials{
				Products: []pingone.EnvironmentBillOfMaterialsProduct{
					{
						Type: "PING_ONE_AUTHORIZE",
					},
					{
						Type: "PING_ONE_BASE",
					},
					{
						Type: "PING_ONE_CREDENTIALS",
					},
					{
						Type: "PING_ONE_DAVINCI",
						Tags: davinciTags,
					},
					{
						Type: "PING_ONE_MFA",
					},
					{
						Type: "PING_ONE_RISK",
					},
					{
						Type: "PING_ONE_VERIFY",
					},
				},
			},
			Description: pingone.PtrString("Test environment created by the PingOne Go SDK"),
			License: pingone.EnvironmentLicense{
				Id: licenseId,
			},
			Name:   name,
			Region: regionCode,
			Type:   "SANDBOX",
		}
	}
)

Functions

func CheckCreated

func CheckCreated(t *testing.T, responseDataObj any, expectedResponseDataType any, httpResponse *http.Response, httpError error)

CheckCreated verifies that an API operation successfully created a resource. The responseDataObj parameter contains the actual response data, expectedResponseDataType specifies the expected type of the response, httpResponse is the HTTP response object, and httpError is any error from the API call. This function validates that the operation returned HTTP 201 Created status and the response data matches the expected type.

func CheckDeleted

func CheckDeleted(t *testing.T, httpResponse *http.Response, httpError error)

CheckDeleted verifies that an API operation successfully deleted a resource. The httpResponse parameter is the HTTP response object and httpError is any error from the API call. This function validates that the operation returned HTTP 204 No Content status, which is the standard response for successful deletion operations.

func CheckFound

func CheckFound(t *testing.T, responseDataObj any, expectedResponseDataType any, httpResponse *http.Response, httpError error)

CheckFound verifies that an API operation successfully retrieved a resource. The responseDataObj parameter contains the actual response data, expectedResponseDataType specifies the expected type of the response, httpResponse is the HTTP response object, and httpError is any error from the API call. This function validates that the operation returned HTTP 200 OK status and the response data matches the expected type.

func CheckNotFound

func CheckNotFound(t *testing.T, responseDataObj any, httpResponse *http.Response, httpError error)

CheckNotFound verifies that an API operation correctly returned a not found error. The responseDataObj parameter contains the actual response data, httpResponse is the HTTP response object, and httpError is any error from the API call. This function validates that the operation returned HTTP 404 Not Found status.

func CheckPingOneAPIErrorResponse

func CheckPingOneAPIErrorResponse(t *testing.T, httpError error, expectedErrorType any, expectedErrorMessageRegex *regexp.Regexp)

func CheckReplaced

func CheckReplaced(t *testing.T, responseDataObj any, expectedResponseDataType any, httpResponse *http.Response, httpError error)

CheckReplaced verifies that an API operation successfully replaced/updated a resource. The responseDataObj parameter contains the actual response data, expectedResponseDataType specifies the expected type of the response, httpResponse is the HTTP response object, and httpError is any error from the API call. This function validates that the operation returned HTTP 200 OK status and the response data matches the expected type.

func RandomResourceName

func RandomResourceName() string

RandomResourceName generates a random resource name suitable for testing purposes. It returns a 10-character string composed of lowercase letters. This function is useful for creating unique test resource names to avoid conflicts in test environments.

func TestClient

func TestClient(svcConfig *config.Configuration) (*pingone.APIClient, error)

TestClient creates a new PingOne API client configured for testing purposes. The svcConfig parameter must be a valid Configuration with authentication credentials and endpoint settings. The client is automatically configured with a "testing" user agent to help identify test traffic in logs. It returns a configured API client or an error if client creation fails.

Types

type CreateConfig

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

CreateConfig contains configuration for environment creation operations. It encapsulates the API client, context, and creation options for creating test environments in PingOne.

func CreateEnvironment

func CreateEnvironment(ctx context.Context, apiClient *pingone.APIClient) *CreateConfig

CreateEnvironment initializes a new CreateConfig for environment creation. The ctx parameter provides the context for API operations, and apiClient must be a configured PingOne API client with appropriate authentication. Use the returned CreateConfig to configure creation options before calling Create.

func (*CreateConfig) IfNotExists

func (e *CreateConfig) IfNotExists() *CreateConfig

IfNotExists configures the creation to not return an error if the environment already exists. When enabled, if an environment with the same configuration already exists, the operation will return the existing environment instead of failing with a conflict error.

type DeleteConfig

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

DeleteConfig contains configuration for environment deletion operations. It encapsulates the API client, context, and deletion options for removing test environments from PingOne.

func DeleteEnvironment

func DeleteEnvironment(ctx context.Context, apiClient *pingone.APIClient) *DeleteConfig

DeleteEnvironment initializes a new DeleteConfig for environment deletion. The ctx parameter provides the context for API operations, and apiClient must be a configured PingOne API client with appropriate authentication. Use the returned DeleteConfig to configure deletion options before calling Delete.

func (*DeleteConfig) IfExists

func (e *DeleteConfig) IfExists() *DeleteConfig

IfExists configures the deletion to not return an error if the environment does not exist. When enabled, if the environment has already been deleted or does not exist, the operation will succeed without error instead of failing with a not found error.

type NewEnvironmentTestSuite

type NewEnvironmentTestSuite struct {
	PingOneTestSuite
	// EnvironmentNamePrefix is prepended to generated environment names.
	EnvironmentNamePrefix string
	// EnvironmentNameSuffix is appended to generated environment names.
	EnvironmentNameSuffix string
	// TestEnvironment contains the created test environment for the current test.
	TestEnvironment *TestEnvironment
	// WithBootstrap determines whether the environment includes full DaVinci features.
	WithBootstrap bool
}

NewEnvironmentTestSuite extends PingOneTestSuite to provide automatic test environment creation. This suite creates a fresh PingOne environment for each test and cleans it up afterward, ensuring test isolation and preventing test interference.

func (*NewEnvironmentTestSuite) SetupSuite

func (s *NewEnvironmentTestSuite) SetupSuite()

SetupSuite initializes the test suite by calling the parent suite setup. This ensures the PingOne API client is properly configured before environment operations.

func (*NewEnvironmentTestSuite) SetupTest

func (s *NewEnvironmentTestSuite) SetupTest()

SetupTest creates a new PingOne environment for each test method. This method requires the PINGONE_ENVIRONMENT_REGION and PINGONE_LICENSE_ID environment variables to be set. It generates a unique environment name using the configured prefix, random string, and suffix. The environment includes all PingOne services configured according to the WithBootstrap setting.

func (*NewEnvironmentTestSuite) TearDownSuite

func (s *NewEnvironmentTestSuite) TearDownSuite()

func (*NewEnvironmentTestSuite) TearDownTest

func (s *NewEnvironmentTestSuite) TearDownTest()

type PingOneTestSuite

type PingOneTestSuite struct {
	suite.Suite
	// ApiClient is the configured PingOne API client for test operations.
	ApiClient *pingone.APIClient
}

PingOneTestSuite provides a base test suite for PingOne API integration tests. It extends testify's Suite with a pre-configured PingOne API client that is automatically set up before tests run and cleaned up afterward.

func (*PingOneTestSuite) SetupSuite

func (s *PingOneTestSuite) SetupSuite()

SetupSuite initializes the test suite by creating a configured API client. This method is called once before all tests in the suite run. If the ApiClient is not already set, it creates a new test client using the default configuration. The test suite will fail if client creation fails.

func (*PingOneTestSuite) SetupTest

func (s *PingOneTestSuite) SetupTest()

SetupTest is called before each individual test method. This method is currently empty but can be overridden by test suites that need per-test setup logic.

func (*PingOneTestSuite) TearDownSuite

func (s *PingOneTestSuite) TearDownSuite()

TearDownSuite cleans up the test suite by clearing the API client. This method is called once after all tests in the suite have completed.

func (*PingOneTestSuite) TearDownTest

func (s *PingOneTestSuite) TearDownTest()

TearDownTest is called after each individual test method. This method is currently empty but can be overridden by test suites that need per-test cleanup logic.

type SharedEnvironmentTestSuite

type SharedEnvironmentTestSuite struct {
	PingOneTestSuite
	// EnvironmentNamePrefix is prepended to generated environment names.
	EnvironmentNamePrefix string
	// EnvironmentNameSuffix is appended to generated environment names.
	EnvironmentNameSuffix string
	// TestEnvironment contains the shared test environment for all tests in the suite.
	TestEnvironment *TestEnvironment
	// WithBootstrap determines whether the environment includes full DaVinci features.
	WithBootstrap bool
}

SharedEnvironmentTestSuite extends PingOneTestSuite to provide a shared test environment. This suite creates a single PingOne environment that is shared across all test methods in the suite, improving test performance by reducing environment creation overhead.

func (*SharedEnvironmentTestSuite) SetupSuite

func (s *SharedEnvironmentTestSuite) SetupSuite()

SetupSuite creates a shared PingOne environment for all test methods in the suite. This method requires the PINGONE_ENVIRONMENT_REGION and PINGONE_LICENSE_ID environment variables to be set. It generates a unique environment name and creates an environment with all PingOne services. The environment is shared across all tests to improve performance.

func (*SharedEnvironmentTestSuite) SetupTest

func (s *SharedEnvironmentTestSuite) SetupTest()

Set up the test with a new environment

func (*SharedEnvironmentTestSuite) TearDownSuite

func (s *SharedEnvironmentTestSuite) TearDownSuite()

func (*SharedEnvironmentTestSuite) TearDownTest

func (s *SharedEnvironmentTestSuite) TearDownTest()

type TestEnvironment

type TestEnvironment struct {
	// EnvironmentCreateRequest contains the configuration used to create the environment.
	EnvironmentCreateRequest pingone.EnvironmentCreateRequest
	// Environment contains the response from PingOne after environment creation.
	Environment *pingone.EnvironmentResponse
}

TestEnvironment represents a PingOne environment used for testing purposes. It contains both the creation request configuration and the resulting environment response after successful creation.

func NewTestEnvironment

func NewTestEnvironment(environment pingone.EnvironmentCreateRequest) *TestEnvironment

NewTestEnvironment creates a new TestEnvironment instance with the provided configuration. The environment parameter must contain valid environment creation settings including name, region, license, and bill of materials. The environment is not created until the Create method is called.

func (*TestEnvironment) Create

func (e *TestEnvironment) Create(request CreateConfig) (err error)

Create creates a new PingOne environment using the configured settings. The request parameter must contain a valid CreateConfig with API client and context. It calls the PingOne API to create the environment and stores the response in the Environment field. Returns an error if the creation fails or if the API returns a non-success status code.

func (*TestEnvironment) Delete

func (e *TestEnvironment) Delete(request DeleteConfig) (err error)

Delete removes the PingOne environment using the configured settings. The request parameter must contain a valid DeleteConfig with API client and context. The Environment field must be populated (from a previous Create operation) unless ifExists is true. Returns an error if the deletion fails or if the environment is nil and ifExists is false.

Jump to

Keyboard shortcuts

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