mocks

package
v0.26.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalRegistry = NewRegistry()

Global registry instance

View Source
var TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
	"microsoft365": providerserver.NewProtocol6WithError(provider.NewMicrosoft365Provider("test", false)()),
}

TestAccProtoV6ProviderFactories provides a map of provider factories specifically configured for acceptance testing scenarios. The Microsoft365 provider is instantiated with testMode=false, which enables production-like behavior such as:

  • Making real HTTP calls to Microsoft Graph API endpoints
  • Requiring valid authentication credentials
  • Interacting with actual Microsoft365 tenant resources
  • Full end-to-end integration testing

This factory is intended for acceptance tests that verify the provider's ability to correctly manage real Microsoft365 resources through the Graph API. These tests require valid credentials and may create, modify, or delete actual resources in a test tenant.

View Source
var TestUnitTestProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
	"microsoft365": providerserver.NewProtocol6WithError(provider.NewMicrosoft365Provider("test", true)()),
}

TestUnitTestProtoV6ProviderFactories provides a map of provider factories specifically configured for unit testing scenarios. The Microsoft365 provider is instantiated with testMode=true, which enables test-specific behavior such as:

  • Using mock HTTP clients instead of real Microsoft Graph API calls
  • Bypassing authentication requirements
  • Using in-memory or stubbed data sources
  • Faster execution without network dependencies

This factory is intended for isolated unit tests that focus on testing provider logic, resource schemas, validation, and state management without making actual API calls to Microsoft365 services.

Functions

func EnsureField

func EnsureField(data map[string]interface{}, fieldName string, defaultValue interface{})

EnsureField ensures that a field exists in a data map If the field doesn't exist, it will be initialized with the provided default value This is particularly useful for ensuring collection fields are initialized in mock responses

func LoadCentralizedTerraformConfig

func LoadCentralizedTerraformConfig(filepath string) string

LoadCentralizedTerraformConfig reads a terraform configuration file from centralized dependencies This is used for loading shared dependency files from the acceptance/terraform_dependencies directory

func LoadJSONResponse

func LoadJSONResponse(filepath string) (map[string]interface{}, error)

LoadJSONResponse loads a JSON response file and returns its contents This is a common utility function used by mock responders to load test response data

func LoadLocalTerraformConfig

func LoadLocalTerraformConfig(filename string) string

LoadLocalTerraformConfig reads a terraform configuration file from the local test directory in services/<resource>/<resource_type>/tests/terraform/acceptance folder. Falls back to unit directory if not found in acceptance.

func LoadTerraformConfigFile

func LoadTerraformConfigFile(filename string) string

LoadTerraformConfigFile reads a terraform configuration file from the localised acceptance test directory in services/<resource>/<resource_type>/tests/terraform/acceptance folder. Deprecated: Use LoadLocalTerraformConfig instead for better clarity

func LoadTerraformTemplateFile

func LoadTerraformTemplateFile(filename string, data interface{}) string

LoadTerraformTemplateFile reads a terraform template file and applies the provided data This is used for

func SetupUnitTestEnvironment

func SetupUnitTestEnvironment(t *testing.T)

func TestAccPreCheck

func TestAccPreCheck(t *testing.T)

TestAccPreCheck verifies necessary test prerequisites

func TestName

func TestName() string

TestName returns the name of the function that called it.

Types

type AuthMock

type AuthMock struct{}

AuthMock provides authentication mock responses

func (*AuthMock) RegisterErrorMocks

func (a *AuthMock) RegisterErrorMocks()

RegisterErrorMocks registers authentication error responses

func (*AuthMock) RegisterMocks

func (a *AuthMock) RegisterMocks()

RegisterMocks registers authentication mock responses

type AuthenticationMocks

type AuthenticationMocks struct {
	TenantID                string
	ClientID                string
	TokenExpiryMinutes      int
	AccessToken             string
	RefreshToken            string
	IDToken                 string
	InstanceDiscoveryResult *InstanceDiscoveryResponse
}

AuthenticationMocks provides mock responses for Azure authentication flows

func NewAuthenticationMocks

func NewAuthenticationMocks() *AuthenticationMocks

NewAuthenticationMocks creates a new instance of AuthenticationMocks with default values

func (*AuthenticationMocks) GraphBetaTokenResponse

func (a *AuthenticationMocks) GraphBetaTokenResponse() []byte

func (*AuthenticationMocks) RegisterMocks

func (a *AuthenticationMocks) RegisterMocks()

RegisterMocks registers all mock responses with httpmock

type DeviceCodeResponse

type DeviceCodeResponse struct {
	UserCode        string `json:"user_code"`
	DeviceCode      string `json:"device_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
	Message         string `json:"message"`
}

DeviceCodeResponse represents the response from the device code endpoint

type ErrorMocks

type ErrorMocks struct{}

ErrorMocks provides mock HTTP responses for graph API errors.

func NewErrorMocks

func NewErrorMocks() *ErrorMocks

NewErrorMocks creates a new instance of ErrorMocks.

func (*ErrorMocks) RegisterMocks

func (m *ErrorMocks) RegisterMocks()

RegisterMocks registers all error-related mock responders.

type InstanceDiscoveryResponse

type InstanceDiscoveryResponse struct {
	TenantDiscoveryEndpoint string          `json:"tenant_discovery_endpoint"`
	ApiVersion              string          `json:"api-version"`
	Metadata                []MetadataEntry `json:"metadata"`
}

InstanceDiscoveryResponse represents the response from the instance discovery endpoint

type MetadataEntry

type MetadataEntry struct {
	Preferred bool     `json:"preferred"`
	Aliases   []string `json:"aliases"`
}

MetadataEntry represents a metadata entry in the instance discovery response

type MockRegistrar

type MockRegistrar interface {
	RegisterMocks()
	RegisterErrorMocks()
}

MockRegistrar defines the interface for mock registrars

type Mocks

type Mocks struct {
	AuthMocks *AuthenticationMocks
	Clients   *client.MockGraphClients
}

Mocks provides a centralized way to manage mock HTTP responses for testing.

func NewMocks

func NewMocks() *Mocks

NewMocks creates a new instance of Mocks, initializing shared mock and set up the mock client with the default http client.

type OpenIDConfigurationResponse

type OpenIDConfigurationResponse struct {
	TokenEndpoint                    string   `json:"token_endpoint"`
	TokenEndpointAuthMethods         []string `json:"token_endpoint_auth_methods_supported"`
	JwksURI                          string   `json:"jwks_uri"`
	ResponseModesSupported           []string `json:"response_modes_supported"`
	SubjectTypesSupported            []string `json:"subject_types_supported"`
	IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
	ResponseTypesSupported           []string `json:"response_types_supported"`
	ScopesSupported                  []string `json:"scopes_supported"`
	Issuer                           string   `json:"issuer"`
	RequestURIParameterSupported     bool     `json:"request_uri_parameter_supported"`
	UserInfoEndpoint                 string   `json:"userinfo_endpoint"`
	AuthorizationEndpoint            string   `json:"authorization_endpoint"`
	DeviceAuthorizationEndpoint      string   `json:"device_authorization_endpoint"`
	HTTPLogoutSupported              bool     `json:"http_logout_supported"`
	FrontchannelLogoutSupported      bool     `json:"frontchannel_logout_supported"`
	EndSessionEndpoint               string   `json:"end_session_endpoint"`
	ClaimsSupported                  []string `json:"claims_supported"`
	TenantRegionScope                string   `json:"tenant_region_scope"`
	CloudGraphHostName               string   `json:"cloud_graph_host_name"`
	MsgraphHost                      string   `json:"msgraph_host"`
	RbacURL                          string   `json:"rbac_url"`
}

OpenIDConfigurationResponse represents the response from the OpenID configuration endpoint

type Registry

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

Registry holds all registered mocks

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new mock registry

func (*Registry) ActivateErrorMocks

func (r *Registry) ActivateErrorMocks(names ...string)

ActivateErrorMocks activates error mocks for specific resources or all if none specified

func (*Registry) ActivateMocks

func (r *Registry) ActivateMocks(names ...string)

ActivateMocks activates specific mocks or all if none specified

func (*Registry) DeactivateAndReset

func (r *Registry) DeactivateAndReset()

DeactivateAndReset deactivates httpmock

func (*Registry) Register

func (r *Registry) Register(name string, mock MockRegistrar)

Register adds a mock to the registry

type TokenResponse

type TokenResponse struct {
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
	ExpiresIn    int    `json:"expires_in"`
	ExtExpiresIn int    `json:"ext_expires_in"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token,omitempty"`
	IDToken      string `json:"id_token,omitempty"`
	ExpiresOn    string `json:"expires_on,omitempty"`
}

TokenResponse represents the response from the token endpoint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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