unit

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: MPL-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvNameHTTPMockerCapture    = "HTTP_MOCKER_CAPTURE"
	EnvNameHTTPMockerReplay     = "HTTP_MOCKER_REPLAY"
	EnvNameHTTPMockerDataUpdate = "HTTP_MOCKER_DATA_UPDATE"
)

Variables

This section is empty.

Functions

func AssertDiagsOK

func AssertDiagsOK(t *testing.T, diags diag.Diagnostics)

func CaptureOrMockTestCaseAndRun added in v1.23.0

func CaptureOrMockTestCaseAndRun(t *testing.T, config MockHTTPDataConfig, testCase *resource.TestCase)

func ConfigYaml added in v1.23.0

func ConfigYaml(capturedData *MockHTTPData) (string, error)

func DownloadOpenAPISpec added in v1.23.0

func DownloadOpenAPISpec(url, specFilePath string) (err error)

func ExtractConfigVariables added in v1.23.0

func ExtractConfigVariables(t *testing.T, config string) map[string]string

func ExtractVersion added in v1.23.0

func ExtractVersion(contentType string) (string, error)

func ExtractVersionRequestResponse added in v1.23.0

func ExtractVersionRequestResponse(headerValueRequest, headerValueResponse string) string

func FailedFilename added in v1.23.0

func FailedFilename(filePath string) string

func InitializeAPISpecPaths added in v1.23.0

func InitializeAPISpecPaths()

func IsCapture added in v1.23.0

func IsCapture() bool

func IsDataUpdate added in v1.23.0

func IsDataUpdate() bool

func IsReplay added in v1.23.0

func IsReplay() bool

func IsTfLogDebug added in v1.26.0

func IsTfLogDebug() bool

func MockConfigFilePath added in v1.23.0

func MockConfigFilePath(t *testing.T) string

func ReadAPISpecPaths added in v1.23.0

func ReadAPISpecPaths() map[string][]APISpecPath

func TFListValue

func TFListValue(t *testing.T, elementType types.ObjectType, tfList any) types.List

func TFObjectValue

func TFObjectValue(t *testing.T, objType types.ObjectType, attributes any) types.Object

func TestAccProviderV6FactoriesWithMock added in v1.23.0

func TestAccProviderV6FactoriesWithMock(t *testing.T, clientModifier HTTPClientModifier) map[string]func() (tfprotov6.ProviderServer, error)

func UpdateMockDataDiffRequest added in v1.23.0

func UpdateMockDataDiffRequest(t *testing.T, stepIndex, diffRequestIndex int, newText string)

func WriteConfigYaml added in v1.23.0

func WriteConfigYaml(filePath, configYaml string) error

Types

type APISpecPath added in v1.23.0

type APISpecPath struct {
	Path string
}

func FindNormalizedPath added in v1.23.0

func FindNormalizedPath(path string, apiSpecPaths *[]APISpecPath) (APISpecPath, error)

func (*APISpecPath) Match added in v1.23.0

func (a *APISpecPath) Match(path string) bool

func (*APISpecPath) Variables added in v1.23.0

func (a *APISpecPath) Variables(path string) map[string]string

type CaptureMockConfigClientModifier added in v1.23.0

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

func NewCaptureMockConfigClientModifier added in v1.23.0

func NewCaptureMockConfigClientModifier(t *testing.T, config *MockHTTPDataConfig, data *MockHTTPData) *CaptureMockConfigClientModifier

func (*CaptureMockConfigClientModifier) ConfigYaml added in v1.23.0

func (c *CaptureMockConfigClientModifier) ConfigYaml() (string, error)

func (*CaptureMockConfigClientModifier) IncreaseStepNumber added in v1.23.0

func (c *CaptureMockConfigClientModifier) IncreaseStepNumber()

func (*CaptureMockConfigClientModifier) ModifyHTTPClient added in v1.23.0

func (c *CaptureMockConfigClientModifier) ModifyHTTPClient(httpClient *http.Client) error

func (*CaptureMockConfigClientModifier) NormalizeCapturedData added in v1.23.0

func (c *CaptureMockConfigClientModifier) NormalizeCapturedData()

func (*CaptureMockConfigClientModifier) ResetHTTPClient added in v1.23.0

func (c *CaptureMockConfigClientModifier) ResetHTTPClient(httpClient *http.Client)

func (*CaptureMockConfigClientModifier) RoundTrip added in v1.23.0

func (*CaptureMockConfigClientModifier) WriteCapturedData added in v1.23.0

func (c *CaptureMockConfigClientModifier) WriteCapturedData(filePath string) error

type HTTPClientModifier added in v1.23.0

type HTTPClientModifier interface {
	ModifyHTTPClient(*http.Client) error
	ResetHTTPClient(*http.Client)
}

type Literal added in v1.23.0

type Literal string

There is an issue when dumping the yaml, if the \n \n sequence is found it will always dump using the DoubleQuotedStyle, workaround by using this custom dumping.

func (Literal) MarshalYAML added in v1.23.0

func (l Literal) MarshalYAML() (any, error)

type MockHTTPData added in v1.23.0

type MockHTTPData struct {
	Variables map[string]string `yaml:"variables"`
	Steps     []stepRequests    `yaml:"steps"`
}

func NewMockHTTPData added in v1.23.0

func NewMockHTTPData(t *testing.T, stepCount int, tfConfigs []string) *MockHTTPData

func ParseTestDataConfigYAML added in v1.23.0

func ParseTestDataConfigYAML(filePath string) (*MockHTTPData, error)

func ReadMockData added in v1.23.0

func ReadMockData(t *testing.T, tfConfigs []string) *MockHTTPData

func (*MockHTTPData) AddRoundtrip added in v1.23.0

func (m *MockHTTPData) AddRoundtrip(t *testing.T, rt *RoundTrip, isDiff bool) error

func (*MockHTTPData) Normalize added in v1.23.0

func (m *MockHTTPData) Normalize()

Normalize happens after all data is captured, as a cluster.name might only be discovered as a variable in later steps

func (*MockHTTPData) UpdateVariables added in v1.23.0

func (m *MockHTTPData) UpdateVariables(t *testing.T, variables map[string]string) error

func (*MockHTTPData) UpdateVariablesIgnoreChanges added in v1.23.0

func (m *MockHTTPData) UpdateVariablesIgnoreChanges(t *testing.T, variables map[string]string) error

type MockHTTPDataConfig added in v1.23.0

type MockHTTPDataConfig struct {
	SideEffect           func() error
	IsDiffSkipSuffixes   []string
	IsDiffMustSubstrings []string
	QueryVars            []string
	AllowMissingRequests bool
	AllowOutOfOrder      bool
}

func (MockHTTPDataConfig) WithAllowOutOfOrder added in v1.23.0

func (c MockHTTPDataConfig) WithAllowOutOfOrder() MockHTTPDataConfig

type MockRoundTripper added in v1.23.0

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

func NewMockRoundTripper added in v1.23.0

func NewMockRoundTripper(t *testing.T, config *MockHTTPDataConfig, data *MockHTTPData) (http.RoundTripper, *MockRoundTripper)

func (*MockRoundTripper) CheckStepRequests added in v1.23.0

func (r *MockRoundTripper) CheckStepRequests(_ *terraform.State) error

func (*MockRoundTripper) IncreaseStepNumberAndInit added in v1.23.0

func (r *MockRoundTripper) IncreaseStepNumberAndInit()

type OpenapiSchema added in v1.23.0

type OpenapiSchema struct {
	Paths map[string]map[string]interface{} `yaml:"paths"`
}

type ProviderMocked added in v1.23.0

type ProviderMocked struct {
	OriginalProvider *provider.MongodbtlasProvider
	ClientModifier   HTTPClientModifier
	// contains filtered or unexported fields
}

func (*ProviderMocked) Configure added in v1.23.0

func (*ProviderMocked) DataSources added in v1.23.0

func (p *ProviderMocked) DataSources(ctx context.Context) []func() datasource.DataSource

func (*ProviderMocked) Metadata added in v1.23.0

func (*ProviderMocked) Resources added in v1.23.0

func (p *ProviderMocked) Resources(ctx context.Context) []func() resource.Resource

func (*ProviderMocked) Schema added in v1.23.0

type RequestInfo added in v1.23.0

type RequestInfo struct {
	Path      string       `yaml:"path"`
	Method    string       `yaml:"method"`
	Version   string       `yaml:"version"`
	Text      string       `yaml:"text"`
	Responses []statusText `yaml:"responses"`
}

func (RequestInfo) MarshalYAML added in v1.23.0

func (i RequestInfo) MarshalYAML() (any, error)

Custom marshaling is necessary to use `flow` style only on response fields (text and responses.*.text)

func (*RequestInfo) Match added in v1.23.0

func (i *RequestInfo) Match(t *testing.T, method, version string, reqURL *url.URL, mockData *MockHTTPData) bool

func (*RequestInfo) NormalizePath added in v1.23.0

func (i *RequestInfo) NormalizePath(reqURL *url.URL) string

func (*RequestInfo) QueryVars added in v1.23.0

func (i *RequestInfo) QueryVars() []string

type RoundTrip added in v1.23.0

type RoundTrip struct {
	Variables   map[string]string
	QueryString string
	Request     RequestInfo
	Response    statusText
	StepNumber  int
}

type TFConfigReplacementType added in v1.23.0

type TFConfigReplacementType int
const (
	TFConfigReplacementString TFConfigReplacementType = iota
)

type VariableChange added in v1.23.0

type VariableChange struct {
	OldName  string
	NewName  string
	OldValue string
	NewValue string
}

type VariablesChangedError added in v1.23.0

type VariablesChangedError struct {
	Changes []VariableChange
}

func (VariablesChangedError) ChangedNamesMap added in v1.23.0

func (e VariablesChangedError) ChangedNamesMap() map[string]string

func (VariablesChangedError) ChangedValuesMap added in v1.23.0

func (e VariablesChangedError) ChangedValuesMap() map[string]string

func (VariablesChangedError) Error added in v1.23.0

func (e VariablesChangedError) Error() string

Jump to

Keyboard shortcuts

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