Documentation
¶
Index ¶
- Variables
- func EnsureField(data map[string]interface{}, fieldName string, defaultValue interface{})
- func LoadCentralizedTerraformConfig(filepath string) string
- func LoadJSONResponse(filepath string) (map[string]interface{}, error)
- func LoadLocalTerraformConfig(filename string) string
- func LoadTerraformConfigFile(filename string) string
- func LoadTerraformTemplateFile(filename string, data interface{}) string
- func SetupUnitTestEnvironment(t *testing.T)
- func TestAccPreCheck(t *testing.T)
- func TestName() string
- type AuthMock
- type AuthenticationMocks
- type DeviceCodeResponse
- type ErrorMocks
- type InstanceDiscoveryResponse
- type MetadataEntry
- type MockRegistrar
- type Mocks
- type OpenIDConfigurationResponse
- type Registry
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
var GlobalRegistry = NewRegistry()
Global registry instance
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
LoadTerraformTemplateFile reads a terraform template file and applies the provided data This is used for
func TestAccPreCheck ¶
TestAccPreCheck verifies necessary test prerequisites
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 ¶
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.
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 (*Registry) ActivateErrorMocks ¶
ActivateErrorMocks activates error mocks for specific resources or all if none specified
func (*Registry) ActivateMocks ¶
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