testutil

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDeployment added in v0.2.0

func CreateDeployment(ctx context.Context, subscriptionId string, cred azcore.TokenCredential, options *arm.ClientOptions, resourceGroupName, deploymentName string, deployment *armresources.Deployment) (*armresources.DeploymentExtended, error)

CreateDeployment will create a resource using arm template. It will return the deployment result entity.

func CreateResourceGroup

func CreateResourceGroup(ctx context.Context, subscriptionId string, cred azcore.TokenCredential, options *arm.ClientOptions, location string) (*armresources.ResourceGroup, func() (*runtime.Poller[armresources.ResourceGroupsClientDeleteResponse], error), error)

CreateResourceGroup will create a resource group with a random generated name: "go-sdk-test-xxx". It will return the created resource group entity, a delegate function to delete the created resource group which can be used for clean up and any error during the creation.

func DeleteResourceGroup

func DeleteResourceGroup(ctx context.Context, subscriptionId string, cred azcore.TokenCredential, options *arm.ClientOptions, resourceGroupName string) (*runtime.Poller[armresources.ResourceGroupsClientDeleteResponse], error)

DeleteResourceGroup will delete the resource group with the given name. It will do the deletion asynchronously and return the poller which can be used to wait for the result.

func GenerateAlphaNumericID added in v1.1.0

func GenerateAlphaNumericID(t *testing.T, prefix string, length int) string

GenerateAlphaNumericID will generate a random alpha numeric ID. When handling live request, the random seed is generated. Otherwise, the random seed is stable and will be stored in recording file. The length parameter is the random part length, not include the prefix part. Deprecated: use github.com/Azure/azure-sdk-for-go/sdk/internal/recording.GenerateAlphaNumericID instead.

func GetCredAndClientOptions

func GetCredAndClientOptions(t *testing.T) (azcore.TokenCredential, *arm.ClientOptions)

GetCredAndClientOptions will create a credential and a client options for test application. They can be used in any Azure resource management client. The client options will initialize the transport for recording client add recording policy to the pipeline. In the record mode, the credential will be a DefaultAzureCredential which combines several common credentials. In the playback mode, the credential will be a fake credential which will bypass truly authorization.

func GetEnv

func GetEnv(key, fallback string) string

GetEnv will return the os env variable and fallback to the given string if env variable not exist. Deprecated: use github.com/Azure/azure-sdk-for-go/sdk/internal/recording.GetEnvVariable instead.

func NewRecordingPolicy

func NewRecordingPolicy(t *testing.T, o *recording.RecordingOptions) policy.Policy

NewRecordingPolicy will create a recording policy which can be used in pipeline. The policy will change the destination of the request to the proxy server and add required header for the recording test.

func PollForTest added in v0.3.0

func PollForTest[T any](ctx context.Context, poller *runtime.Poller[T]) (*T, error)

PollForTest will poll result according to the recording mode: Playback: customer poll loop until get result Others: use original poll until done

func StartRecording

func StartRecording(t *testing.T, pathToPackage string) func()

StartRecording starts the recording with the path to store recording file. It will return a delegate function to stop recording.

func StopRecording

func StopRecording(t *testing.T)

StopRecording stops the recording.

Types

type FakeCredential added in v1.0.0

type FakeCredential struct {
}

FakeCredential is an empty credential for testing.

func (*FakeCredential) GetToken added in v1.0.0

GetToken provide a fake access token.

Jump to

Keyboard shortcuts

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