mocks

package
v0.0.0-...-16b5795 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: OSL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package mocks provides mock implementations of Azure SDK clients for testing

Index

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 BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a bool.

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

func CreateMockHTTPResponse(statusCode int, body string) *http.Response

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 Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr returns a pointer to a float64.

func Int32Ptr

func Int32Ptr(i int32) *int32

Int32Ptr returns a pointer to an int32.

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr returns a pointer to an int64.

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).

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a string.

Types

type LegacyOpt

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

func WithCosts(onDemand, commitment, savings float64) LegacyOpt

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

func WithLookBack(period string) LegacyOpt

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

func WithNormalizedQuantity(qty float32) LegacyOpt

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

func WithNormalizedSize(size string) LegacyOpt

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

func WithQuantity(qty float64) LegacyOpt

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

func WithRegion(region string) LegacyOpt

WithRegion sets the outer Location field used by the helper as "Region".

func WithSKU

func WithSKU(sku string) LegacyOpt

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

func WithSKUProperty(key, value string) LegacyOpt

WithSKUProperty adds a key/value pair to SKUProperties. Use this when a test needs to cover specific property keys beyond the SKUName shortcut.

func WithScope

func WithScope(scope string) LegacyOpt

WithScope overrides the default "Shared" scope ("Shared" or "Single").

func WithTerm

func WithTerm(term string) LegacyOpt

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

type MockHTTPClient struct {
	mock.Mock
	ResponseBody string
	StatusCode   int
}

MockHTTPClient mocks an HTTP client.

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do performs the mock HTTP request.

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

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

More returns whether there are more pages.

func (*MockReservationsSummariesPager) NextPage

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

NextPage returns the next page of results.

type ModernOpt

ModernOpt configures a *ModernReservationRecommendation fixture built by BuildModernReservationRecommendation. Mirror of LegacyOpt.

func WithModernCosts

func WithModernCosts(onDemand, commitment, savings float64) ModernOpt

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

func WithModernCurrency(currency string) ModernOpt

WithModernCurrency rewrites the currency on every cost Amount already set (apply after WithModernCosts). An empty currency clears it.

func WithModernInnerRegion

func WithModernInnerRegion(region string) ModernOpt

WithModernInnerRegion clears the outer Location and sets the inner Properties.Location instead — exercises the fallback path.

func WithModernLookBack

func WithModernLookBack(days *int32) ModernOpt

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

func WithModernNormalizedQuantity(qty float32) ModernOpt

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

func WithModernNormalizedSize(size string) ModernOpt

WithModernNormalizedSize populates NormalizedSize (second-preference source for ResourceType on Modern). Counted by RecommendedQuantityNormalized, not RecommendedQuantity (issue #1540).

func WithModernQuantity

func WithModernQuantity(qty float64) ModernOpt

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

func WithModernRegion(region string) ModernOpt

WithModernRegion sets the outer envelope Location (the preferred source for Region extraction).

func WithModernSKUName

func WithModernSKUName(sku string) ModernOpt

WithModernSKUName sets the top-level Modern SKUName — the preferred source for ResourceType on Modern recs.

func WithModernScope

func WithModernScope(scope string) ModernOpt

WithModernScope overrides the default "Shared" scope.

func WithModernTerm

func WithModernTerm(term string) ModernOpt

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.

func (*PricingHTTP) Do

func (p *PricingHTTP) Do(req *http.Request) (*http.Response, error)

Do implements the HTTPClient interface the service clients accept.

Jump to

Keyboard shortcuts

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