Documentation
¶
Overview ¶
Package mocks provides mock implementations of Azure SDK clients for testing
Index ¶
- func AssertConsumptionUnitVariants(t *testing.T, recs []common.Recommendation, price1y, price3y float64)
- func BoolPtr(b bool) *bool
- func BuildLegacyReservationRecommendation(opts ...LegacyOpt) *armconsumption.LegacyReservationRecommendation
- func BuildModernReservationRecommendation(opts ...ModernOpt) *armconsumption.ModernReservationRecommendation
- func ConsumptionUnitFixtures(sku, region string) []armconsumption.ReservationRecommendationClassification
- func CreateMockHTTPResponse(statusCode int, body string) *http.Response
- func CreateSampleRedisPricingResponse() string
- func CreateSampleResourceSKUs(region string) []*armcompute.ResourceSKU
- func CreateSampleSQLPricingResponse() string
- func CreateSampleVMPricingResponse() string
- func Float64Ptr(f float64) *float64
- func Int32Ptr(i int32) *int32
- func Int64Ptr(i int64) *int64
- func ReservationRow(service, product, region, armSKU, skuName, meterName, term string, ...) map[string]any
- func StringPtr(s string) *string
- type LegacyOpt
- func WithCosts(onDemand, commitment, savings float64) LegacyOpt
- func WithLookBack(period string) LegacyOpt
- func WithNilProperties() LegacyOpt
- func WithNormalizedQuantity(qty float32) LegacyOpt
- func WithNormalizedSize(size string) LegacyOpt
- func WithQuantity(qty float64) LegacyOpt
- func WithRegion(region string) LegacyOpt
- func WithSKU(sku string) LegacyOpt
- func WithSKUProperty(key, value string) LegacyOpt
- func WithScope(scope string) LegacyOpt
- func WithTerm(term string) LegacyOpt
- func WithoutNormalizedQuantity() LegacyOpt
- type MockHTTPClient
- type MockRecommendationsPager
- type MockReservationsSummariesPager
- type MockResourceSKUsPager
- type ModernOpt
- func WithModernCosts(onDemand, commitment, savings float64) ModernOpt
- func WithModernCurrency(currency string) ModernOpt
- func WithModernInnerRegion(region string) ModernOpt
- func WithModernLookBack(days *int32) ModernOpt
- func WithModernNilProperties() ModernOpt
- func WithModernNormalizedQuantity(qty float32) ModernOpt
- func WithModernNormalizedSize(size string) ModernOpt
- func WithModernQuantity(qty float64) ModernOpt
- func WithModernRegion(region string) ModernOpt
- func WithModernSKUName(sku string) ModernOpt
- func WithModernScope(scope string) ModernOpt
- func WithModernTerm(term string) ModernOpt
- type PricingHTTP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertConsumptionUnitVariants ¶
func AssertConsumptionUnitVariants(t *testing.T, recs []common.Recommendation, price1y, price3y float64)
AssertConsumptionUnitVariants checks the four variants produced from ConsumptionUnitFixtures given the 1y and 3y per-unit reservation prices: monthly on-demand and savings, upfront commitment = Count x price, monthly variants with no upfront and price/term-months recurring.
func BuildLegacyReservationRecommendation ¶
func BuildLegacyReservationRecommendation(opts ...LegacyOpt) *armconsumption.LegacyReservationRecommendation
BuildLegacyReservationRecommendation returns a fully-typed SDK *LegacyReservationRecommendation (implements ReservationRecommendationClassification) with sensible defaults. Apply LegacyOpt functions to override specific fields.
Defaults match a plausible VM reservation recommendation: location "eastus", scope "Shared", term "P1Y", quantity 1, zero costs/savings, empty SKU properties. Tests that assert populated fields must override via With* helpers.
func BuildModernReservationRecommendation ¶
func BuildModernReservationRecommendation(opts ...ModernOpt) *armconsumption.ModernReservationRecommendation
BuildModernReservationRecommendation returns an SDK-typed *ModernReservationRecommendation (MCA billing account shape). Defaults mirror the Legacy builder: "eastus" location, "Shared" scope, "P1Y" term, quantity 1, empty SKU. Cost fields use Azure's *Amount wrapper — pass WithModernCosts or leave them nil to exercise the amountValue nil-guard.
func ConsumptionUnitFixtures ¶
func ConsumptionUnitFixtures(sku, region string) []armconsumption.ReservationRecommendationClassification
ConsumptionUnitFixtures returns one 1-year legacy recommendation (7-day window) and one 3-year modern recommendation (30-day window) for sku in region, both for 2 units, so a service test can cover both response shapes, both terms and two window lengths in a single GetRecommendations call.
func CreateMockHTTPResponse ¶
CreateMockHTTPResponse creates a mock HTTP response.
func CreateSampleRedisPricingResponse ¶
func CreateSampleRedisPricingResponse() string
CreateSampleRedisPricingResponse creates a sample Redis pricing response for testing.
func CreateSampleResourceSKUs ¶
func CreateSampleResourceSKUs(region string) []*armcompute.ResourceSKU
CreateSampleResourceSKUs creates sample resource SKUs for testing.
func CreateSampleSQLPricingResponse ¶
func CreateSampleSQLPricingResponse() string
CreateSampleSQLPricingResponse creates a sample SQL pricing response for testing.
func CreateSampleVMPricingResponse ¶
func CreateSampleVMPricingResponse() string
CreateSampleVMPricingResponse uses synthetic prices, not a live Azure quote.
func ReservationRow ¶
func ReservationRow(service, product, region, armSKU, skuName, meterName, term string, price float64) map[string]any
ReservationRow builds one priceType 'Reservation' retail row. price is the term total per unit, as the Retail Prices API reports it (unitOfMeasure "1 Hour" notwithstanding).
Types ¶
type LegacyOpt ¶
type LegacyOpt func(*armconsumption.LegacyReservationRecommendation, *armconsumption.LegacyReservationRecommendationProperties)
LegacyOpt configures a LegacyReservationRecommendation fixture built by BuildLegacyReservationRecommendation. Use the With* helpers in this file rather than constructing the SDK types by hand — the nested pointer shape makes ad-hoc literals verbose and error-prone.
func WithCosts ¶
WithCosts sets the three cost fields in one call. Zero values are written as explicit pointers so the converter sees "non-nil but zero" (distinct from "field absent").
func WithLookBack ¶
WithLookBack sets the legacy lookBackPeriod string (for example "Last30Days"). An empty string clears the field, exercising the missing-lookback guard.
func WithNilProperties ¶
func WithNilProperties() LegacyOpt
WithNilProperties zeroes the Properties field, exercising the converter's nil-guard.
func WithNormalizedQuantity ¶
WithNormalizedQuantity overrides RecommendedQuantityNormalized alone, so a test can express the real shape the normalization ratio produces: e.g. 4 x Standard_D8s_v3 recommended, 16 x Standard_D2s_v3 normalized. Pass it after WithQuantity, which sets both.
func WithNormalizedSize ¶
WithNormalizedSize populates NormalizedSize, the ResourceType source used when no SKU property names the actual SKU. It is counted by RecommendedQuantityNormalized, not RecommendedQuantity (issue #1540).
func WithQuantity ¶
WithQuantity overrides BOTH recommended quantities, modeling the common case where the recommended SKU is already the family's base size so the normalized and un-normalized counts agree. Use float values (e.g. 0.5, 2.7) to cover the float→int truncation contract.
Setting both matters because the converter pairs each resource-type source with the quantity expressed in that source's units (issue #1540): a fixture that set only RecommendedQuantity while naming a NormalizedSize would describe a payload with no valid pairing. Use WithNormalizedQuantity to make the two differ deliberately.
func WithRegion ¶
WithRegion sets the outer Location field used by the helper as "Region".
func WithSKU ¶
WithSKU is a convenience that seeds SKUProperties with a single `{Name: "SKUName", Value: sku}` entry — the actual SKU, which the converter prefers over NormalizedSize because RecommendedQuantity counts it.
func WithSKUProperty ¶
WithSKUProperty adds a key/value pair to SKUProperties. Use this when a test needs to cover specific property keys beyond the SKUName shortcut.
func WithTerm ¶
WithTerm overrides the Azure term (e.g. "P1Y", "P3Y"). Pass an empty string to exercise the "missing term defaults to 1yr" path.
func WithoutNormalizedQuantity ¶
func WithoutNormalizedQuantity() LegacyOpt
WithoutNormalizedQuantity clears RecommendedQuantityNormalized, modeling a payload that names a NormalizedSize but gives no count in its units.
type MockHTTPClient ¶
MockHTTPClient mocks an HTTP client.
type MockRecommendationsPager ¶
type MockRecommendationsPager struct {
mock.Mock
Results []armconsumption.ReservationRecommendationClassification
HasMore bool
// contains filtered or unexported fields
}
MockRecommendationsPager mocks the recommendations pager.
func (*MockRecommendationsPager) More ¶
func (p *MockRecommendationsPager) More() bool
More returns whether there are more pages.
func (*MockRecommendationsPager) NextPage ¶
func (p *MockRecommendationsPager) NextPage(ctx context.Context) (armconsumption.ReservationRecommendationsClientListResponse, error)
NextPage returns the next page of results.
type MockReservationsSummariesPager ¶
type MockReservationsSummariesPager struct {
Results []*armconsumption.ReservationSummary
HasMore bool
// contains filtered or unexported fields
}
MockReservationsSummariesPager mocks the reservations summaries pager returned by armconsumption.ReservationsSummariesClient.NewListPager. Set Results + HasMore before use; Results are returned on the first NextPage call and More() returns false on the second call.
func (*MockReservationsSummariesPager) More ¶
func (p *MockReservationsSummariesPager) More() bool
More returns whether there are more pages.
func (*MockReservationsSummariesPager) NextPage ¶
func (p *MockReservationsSummariesPager) NextPage(ctx context.Context) (armconsumption.ReservationsSummariesClientListResponse, error)
NextPage returns the next page of results.
type MockResourceSKUsPager ¶
type MockResourceSKUsPager struct {
mock.Mock
Results []*armcompute.ResourceSKU
HasMore bool
// contains filtered or unexported fields
}
MockResourceSKUsPager mocks the resource SKUs pager.
func (*MockResourceSKUsPager) More ¶
func (p *MockResourceSKUsPager) More() bool
More returns whether there are more pages.
func (*MockResourceSKUsPager) NextPage ¶
func (p *MockResourceSKUsPager) NextPage(ctx context.Context) (armcompute.ResourceSKUsClientListResponse, error)
NextPage returns the next page of results.
type ModernOpt ¶
type ModernOpt func(*armconsumption.ModernReservationRecommendation, *armconsumption.ModernReservationRecommendationProperties)
ModernOpt configures a *ModernReservationRecommendation fixture built by BuildModernReservationRecommendation. Mirror of LegacyOpt.
func WithModernCosts ¶
WithModernCosts sets the three *Amount cost fields. All three receive the same currency ("USD" default); pass an empty currency to cover the "currency not sent" edge case (the converter discards currency anyway).
func WithModernCurrency ¶
WithModernCurrency rewrites the currency on every cost Amount already set (apply after WithModernCosts). An empty currency clears it.
func WithModernInnerRegion ¶
WithModernInnerRegion clears the outer Location and sets the inner Properties.Location instead — exercises the fallback path.
func WithModernLookBack ¶
WithModernLookBack sets the modern integer lookBackPeriod. A nil value clears the field, exercising the missing-lookback guard.
func WithModernNilProperties ¶
func WithModernNilProperties() ModernOpt
WithModernNilProperties zeroes Properties, exercising the guard.
func WithModernNormalizedQuantity ¶
WithModernNormalizedQuantity overrides RecommendedQuantityNormalized alone, so a test can make the normalized and un-normalized counts differ. Pass it after WithModernQuantity, which sets both.
func WithModernNormalizedSize ¶
WithModernNormalizedSize populates NormalizedSize (second-preference source for ResourceType on Modern). Counted by RecommendedQuantityNormalized, not RecommendedQuantity (issue #1540).
func WithModernQuantity ¶
WithModernQuantity overrides BOTH recommended quantities, for the same reason as the Legacy WithQuantity: the converter pairs each resource-type source with the quantity in that source's units (issue #1540).
func WithModernRegion ¶
WithModernRegion sets the outer envelope Location (the preferred source for Region extraction).
func WithModernSKUName ¶
WithModernSKUName sets the top-level Modern SKUName — the preferred source for ResourceType on Modern recs.
func WithModernScope ¶
WithModernScope overrides the default "Shared" scope.
func WithModernTerm ¶
WithModernTerm overrides the Azure term. Empty string clears the field entirely to exercise the "missing defaults to 1yr" path.
type PricingHTTP ¶
type PricingHTTP struct {
Items []map[string]any
FailMatch string
// Err, when set, is returned from every request (a transport failure).
Err error
// contains filtered or unexported fields
}
PricingHTTP serves a fixed Retail Prices API page and counts requests. A request whose URL contains FailMatch gets an HTTP 500, so a test can make the lookup for one SKU fail while the others succeed. The rows are hand-built (synthetic prices, not a live Azure quote).
func (*PricingHTTP) Calls ¶
func (p *PricingHTTP) Calls() int
Calls returns the number of requests served so far.