fake

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0, Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const Region = "eastus"
View Source
const RegionNonZonal = "westcentralus"

Variables

View Source
var ResourceSkus = make(map[string][]compute.ResourceSku)

ResourceSkus is a map of location to resource skus

Functions

func MakeBackendAddressPoolID

func MakeBackendAddressPoolID(resourceGroupName, loadBalancerName string, backendAddressPoolName string) string

func MakeLoadBalancerID

func MakeLoadBalancerID(resourceGroupName, loadBalancerName string) string

func NewProductPrice

func NewProductPrice(instanceType string, price float64) client.Item

func NewSpotProductPrice

func NewSpotProductPrice(instanceType string, price float64) client.Item

Types

type AtomicError

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

func (*AtomicError) Get

func (e *AtomicError) Get() error

Get is equivalent to the error being called, so we increase number of calls in this function

func (*AtomicError) IsNil

func (e *AtomicError) IsNil() bool

func (*AtomicError) Reset

func (e *AtomicError) Reset()

func (*AtomicError) Set

func (e *AtomicError) Set(err error, opts ...AtomicErrorOption)

type AtomicErrorOption

type AtomicErrorOption func(atomicError *AtomicError)

func MaxCalls

func MaxCalls(maxCalls int) AtomicErrorOption

type AtomicPtr

type AtomicPtr[T any] struct {
	// contains filtered or unexported fields
}

AtomicPtr is intended for use in mocks to easily expose variables for use in testing. It makes setting and retrieving the values race free by wrapping the pointer itself in a mutex. There is no Get() method, but instead a Clone() method deep copies the object being stored by serializing/de-serializing it from JSON. This pattern shouldn't be followed anywhere else but is an easy way to eliminate races in our tests.

func (*AtomicPtr[T]) Clone

func (a *AtomicPtr[T]) Clone() *T

func (*AtomicPtr[T]) IsNil

func (a *AtomicPtr[T]) IsNil() bool

func (*AtomicPtr[T]) Reset

func (a *AtomicPtr[T]) Reset()

func (*AtomicPtr[T]) Set

func (a *AtomicPtr[T]) Set(v *T)

type AtomicPtrSlice

type AtomicPtrSlice[T any] struct {
	// contains filtered or unexported fields
}

AtomicPtrSlice exposes a slice of a pointer type in a race-free manner.

func (*AtomicPtrSlice[T]) Append

func (a *AtomicPtrSlice[T]) Append(input ...*T)

func (*AtomicPtrSlice[T]) Get

func (a *AtomicPtrSlice[T]) Get(index int) *T

func (*AtomicPtrSlice[T]) Len

func (a *AtomicPtrSlice[T]) Len() int

func (*AtomicPtrSlice[T]) Reset

func (a *AtomicPtrSlice[T]) Reset()

type AtomicPtrStack

type AtomicPtrStack[T any] struct {
	// contains filtered or unexported fields
}

AtomicPtrStack exposes a slice of a pointer type in a race-free manner. The interface is just enough to replace the set.Set usage in our previous tests.

func (*AtomicPtrStack[T]) Add

func (a *AtomicPtrStack[T]) Add(input *T)

func (*AtomicPtrStack[T]) Len

func (a *AtomicPtrStack[T]) Len() int

func (*AtomicPtrStack[T]) Pop

func (a *AtomicPtrStack[T]) Pop() *T

func (*AtomicPtrStack[T]) Reset

func (a *AtomicPtrStack[T]) Reset()

type AzureResourceGraphAPI

type AzureResourceGraphAPI struct {
	AzureResourceGraphBehavior
}

func (*AzureResourceGraphAPI) Reset

func (c *AzureResourceGraphAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type AzureResourceGraphBehavior

type AzureResourceGraphBehavior struct {
	AzureResourceGraphResourcesBehavior MockedFunction[AzureResourceGraphResourcesInput, armresourcegraph.ClientResourcesResponse]
	VirtualMachinesAPI                  *VirtualMachinesAPI
	ResourceGroup                       string
}

type AzureResourceGraphResourcesInput

type AzureResourceGraphResourcesInput struct {
	Query   armresourcegraph.QueryRequest
	Options *armresourcegraph.ClientResourcesOptions
}

type CommunityGalleryImageVersionsAPI

type CommunityGalleryImageVersionsAPI struct {
	ImageVersions AtomicPtrSlice[armcompute.CommunityGalleryImageVersion]
}

func (*CommunityGalleryImageVersionsAPI) NewListPager

func (c *CommunityGalleryImageVersionsAPI) NewListPager(_ string, _ string, _ string, _ *armcompute.CommunityGalleryImageVersionsClientListOptions) *runtime.Pager[armcompute.CommunityGalleryImageVersionsClientListResponse]

NewListPager returns a new pager to return the next page of CommunityGalleryImageVersionsClientListResponse

func (*CommunityGalleryImageVersionsAPI) Reset

type LoadBalancersAPI

type LoadBalancersAPI struct {
	LoadBalancersBehavior
}

func (*LoadBalancersAPI) Get

func (*LoadBalancersAPI) Reset

func (api *LoadBalancersAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type LoadBalancersBehavior

type LoadBalancersBehavior struct {
	LoadBalancers sync.Map
}

type MockHandler

type MockHandler[T any] struct {
	// contains filtered or unexported fields
}

MockHandler returns a pre-defined result or error.

func (MockHandler[T]) Done

func (h MockHandler[T]) Done() bool

Done returns true if the LRO has reached a terminal state. TrivialHandler is always done.

func (MockHandler[T]) Poll

func (h MockHandler[T]) Poll(context.Context) (*http.Response, error)

Poll fetches the latest state of the LRO.

func (MockHandler[T]) Result

func (h MockHandler[T]) Result(_ context.Context, result *T) error

Result is called once the LRO has reached a terminal state. It populates the out parameter with the result of the operation.

type MockSkuClientSingleton

type MockSkuClientSingleton struct {
	SKUClient *ResourceSKUsAPI
}

func (*MockSkuClientSingleton) GetInstance

func (sc *MockSkuClientSingleton) GetInstance() skewer.ResourceClient

func (*MockSkuClientSingleton) Reset

func (sc *MockSkuClientSingleton) Reset()

type MockedFunction

type MockedFunction[I any, O any] struct {
	Output          AtomicPtr[O]      // Output to return on call to this function
	CalledWithInput AtomicPtrStack[I] // Stack used to keep track of passed input to this function
	Error           AtomicError       // Error to return a certain number of times defined by custom error options
	// contains filtered or unexported fields
}

func (*MockedFunction[I, O]) Calls

func (m *MockedFunction[I, O]) Calls() int

func (*MockedFunction[I, O]) FailedCalls

func (m *MockedFunction[I, O]) FailedCalls() int

func (*MockedFunction[I, O]) Invoke

func (m *MockedFunction[I, O]) Invoke(input *I, defaultTransformer func(*I) (O, error)) (O, error)

func (*MockedFunction[I, O]) Reset

func (m *MockedFunction[I, O]) Reset()

Reset must be called between tests otherwise tests will pollute each other.

func (*MockedFunction[I, O]) SuccessfulCalls

func (m *MockedFunction[I, O]) SuccessfulCalls() int

type MockedLRO

type MockedLRO[I any, O any] struct {
	MockedFunction[I, O]
	BeginError AtomicError // Error to return a certain number of times defined by custom error options (for Begin)
}

func (*MockedLRO[I, O]) Calls

func (m *MockedLRO[I, O]) Calls() int

func (*MockedLRO[I, O]) FailedCalls

func (m *MockedLRO[I, O]) FailedCalls() int

func (*MockedLRO[I, O]) Invoke

func (m *MockedLRO[I, O]) Invoke(input *I, defaultTransformer func(*I) (*O, error)) (*runtime.Poller[O], error)

func (*MockedLRO[I, O]) Reset

func (m *MockedLRO[I, O]) Reset()

Reset must be called between tests otherwise tests will pollute each other.

func (*MockedLRO[I, O]) SuccessfulCalls

func (m *MockedLRO[I, O]) SuccessfulCalls() int

type NetworkInterfaceCreateOrUpdateInput

type NetworkInterfaceCreateOrUpdateInput struct {
	ResourceGroupName string
	InterfaceName     string
	Interface         armnetwork.Interface
	Options           *armnetwork.InterfacesClientBeginCreateOrUpdateOptions
}

type NetworkInterfaceDeleteInput

type NetworkInterfaceDeleteInput struct {
	ResourceGroupName, InterfaceName string
}

type NetworkInterfacesAPI

type NetworkInterfacesAPI struct {
	// instance.NetworkInterfacesAPI
	NetworkInterfacesBehavior
}

func (*NetworkInterfacesAPI) BeginDelete

func (*NetworkInterfacesAPI) Get

func (*NetworkInterfacesAPI) Reset

func (c *NetworkInterfacesAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type NetworkInterfacesBehavior

type NetworkInterfacesBehavior struct {
	NetworkInterfacesCreateOrUpdateBehavior MockedLRO[NetworkInterfaceCreateOrUpdateInput, armnetwork.InterfacesClientCreateOrUpdateResponse]
	NetworkInterfacesDeleteBehavior         MockedLRO[NetworkInterfaceDeleteInput, armnetwork.InterfacesClientDeleteResponse]
	NetworkInterfaces                       sync.Map
}

type PricingAPI

type PricingAPI struct {
	client.PricingAPI
	PricingBehavior
}

func (*PricingAPI) GetProductsPricePages

func (p *PricingAPI) GetProductsPricePages(_ context.Context, _ []*client.Filter, fn func(output *client.ProductsPricePage)) error

func (*PricingAPI) Reset

func (p *PricingAPI) Reset()

type PricingBehavior

type PricingBehavior struct {
	NextError         AtomicError
	ProductsPricePage AtomicPtr[client.ProductsPricePage]
}

type ResourceSKUsAPI

type ResourceSKUsAPI struct {
	Location string
}

func (*ResourceSKUsAPI) ListComplete

func (*ResourceSKUsAPI) Reset

func (s *ResourceSKUsAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type VirtualMachineCreateOrUpdateInput

type VirtualMachineCreateOrUpdateInput struct {
	ResourceGroupName string
	VMName            string
	VM                armcompute.VirtualMachine
	Options           *armcompute.VirtualMachinesClientBeginCreateOrUpdateOptions
}

type VirtualMachineDeleteInput

type VirtualMachineDeleteInput struct {
	ResourceGroupName string
	VMName            string
	Options           *armcompute.VirtualMachinesClientBeginDeleteOptions
}

type VirtualMachineExtensionCreateOrUpdateInput

type VirtualMachineExtensionCreateOrUpdateInput struct {
	ResourceGroupName           string
	VirtualMachineName          string
	VirtualMachineExtensionName string
	VirtualMachineExtension     armcompute.VirtualMachineExtension
	Options                     *armcompute.VirtualMachineExtensionsClientBeginCreateOrUpdateOptions
}

type VirtualMachineExtensionsAPI

type VirtualMachineExtensionsAPI struct {
	// instance.VirtualMachineExtensionsAPI
	VirtualMachineExtensionsBehavior
}

func (*VirtualMachineExtensionsAPI) Reset

func (c *VirtualMachineExtensionsAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type VirtualMachineExtensionsBehavior

type VirtualMachineExtensionsBehavior struct {
	VirtualMachineExtensionsCreateOrUpdateBehavior MockedLRO[VirtualMachineExtensionCreateOrUpdateInput, armcompute.VirtualMachineExtensionsClientCreateOrUpdateResponse]
}

type VirtualMachineGetInput

type VirtualMachineGetInput struct {
	ResourceGroupName string
	VMName            string
	Options           *armcompute.VirtualMachinesClientGetOptions
}

type VirtualMachineUpdateInput

type VirtualMachineUpdateInput struct {
	ResourceGroupName string
	VMName            string
	Updates           armcompute.VirtualMachineUpdate
	Options           *armcompute.VirtualMachinesClientBeginUpdateOptions
}

type VirtualMachinesAPI

type VirtualMachinesAPI struct {
	// TODO: document the implications of embedding vs. not embedding the interface here
	// instance.VirtualMachinesAPI // - this is the interface we are mocking.
	VirtualMachinesBehavior
}

func (*VirtualMachinesAPI) Get

func (*VirtualMachinesAPI) Reset

func (c *VirtualMachinesAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

Jump to

Keyboard shortcuts

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