testcommon

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Contains common helpers for TESTS ONLY

Contains common helpers for TESTS ONLY

Contains common helpers for TESTS ONLY

Index

Constants

View Source
const (
	DefaultEndpointSuffix       = "core.windows.net/"
	DefaultBlobEndpointSuffix   = "blob.core.windows.net/"
	AccountNameEnvVar           = "AZURE_STORAGE_ACCOUNT_NAME"
	AccountKeyEnvVar            = "AZURE_STORAGE_ACCOUNT_KEY"
	DefaultEndpointSuffixEnvVar = "AZURE_STORAGE_ENDPOINT_SUFFIX"
	SubscriptionID              = "SUBSCRIPTION_ID"
	ResourceGroupName           = "RESOURCE_GROUP_NAME"
)
View Source
const (
	FakeStorageAccount = "fakestorage"
	FakeStorageURL     = "https://fakestorage.blob.core.windows.net"
	FakeToken          = "faketoken"
)
View Source
const (
	RecordingDirectory          = "sdk/storage/azblob/testdata"
	ContainerPrefix             = "goc"
	BlobPrefix                  = "gotestblob"
	BlockBlobDefaultData        = "GoBlockBlobData"
	InvalidHeaderErrorSubstring = "invalid header field" // error thrown by the http client
)
View Source
const (
	EncryptionScopeEnvVar = "AZURE_STORAGE_ENCRYPTION_SCOPE"
)

Variables

View Source
var (
	BlobContentType        = "my_type"
	BlobContentDisposition = "my_disposition"
	BlobCacheControl       = "control"
	BlobContentLanguage    = "my_language"
	BlobContentEncoding    = "my_encoding"
)
View Source
var BasicBlobTagsMap = map[string]string{
	"azure": "blob",
	"blob":  "sdk",
	"sdk":   "go",
}
View Source
var BasicMetadata = map[string]*string{"Foo": to.Ptr("bar")}
View Source
var SpecialCharBlobTagsMap = map[string]string{
	"+-./:=_ ":        "firsttag",
	"tag2":            "+-./:=_",
	"+-./:=_1":        "+-./:=_",
	"Microsoft Azure": "Azure Storage",
	"Storage+SDK":     "SDK/GO",
	"GO ":             ".Net",
}
View Source
var TestCPKByValue = blob.CPKInfo{
	EncryptionKey:       &testEncryptedKey,
	EncryptionKeySHA256: &testEncryptedHash,
	EncryptionAlgorithm: &testEncryptionAlgorithm,
}
View Source
var TestInvalidCPKByScope = blob.CPKScopeInfo{
	EncryptionScope: &testInvalidEncryptedScope,
}
View Source
var TestInvalidCPKByValue = blob.CPKInfo{
	EncryptionKey:       &testInvalidEncryptedKey,
	EncryptionKeySHA256: &testInvalidEncryptedHash,
	EncryptionAlgorithm: &testEncryptionAlgorithm,
}

Functions

func AfterTest

func AfterTest(t *testing.T, suite string, test string)

func BeforeTest

func BeforeTest(t *testing.T, suite string, test string)

func BlobListToMap

func BlobListToMap(list []string) map[string]bool

func BlockIDIntToBase64

func BlockIDIntToBase64(blockID int) string

BlockIDIntToBase64 functions convert an int block ID to a base-64 string and vice versa

func CreateNewAppendBlob added in v1.2.0

func CreateNewAppendBlob(ctx context.Context, _require *require.Assertions, appendBlobName string, containerClient *container.Client) *appendblob.Client

func CreateNewBlobs

func CreateNewBlobs(ctx context.Context, _require *require.Assertions, blobNames []string, containerClient *container.Client)

func CreateNewBlobsListTier added in v1.2.0

func CreateNewBlobsListTier(ctx context.Context, _require *require.Assertions, blobNames []string, containerClient *container.Client, tier *blob.AccessTier)

func CreateNewBlockBlob

func CreateNewBlockBlob(ctx context.Context, _require *require.Assertions, blockBlobName string, containerClient *container.Client) *blockblob.Client

func CreateNewBlockBlobWithCPK

func CreateNewBlockBlobWithCPK(ctx context.Context, _require *require.Assertions, blockBlobName string, containerClient *container.Client, cpkInfo *blob.CPKInfo, cpkScopeInfo *blob.CPKScopeInfo) (bbClient *blockblob.Client)

func CreateNewContainer

func CreateNewContainer(ctx context.Context, _require *require.Assertions, containerName string, serviceClient *service.Client) *container.Client

func DeleteContainer

func DeleteContainer(ctx context.Context, _require *require.Assertions, containerClient *container.Client)

func DeleteContainerUsingManagementClient added in v1.1.0

func DeleteContainerUsingManagementClient(_require *require.Assertions, accountType TestAccountType, containerName string)

func DisableSoftDelete

func DisableSoftDelete(ctx context.Context, _require *require.Assertions, client *service.Client)

func EnableSoftDelete

func EnableSoftDelete(ctx context.Context, _require *require.Assertions, client *service.Client)

func GenerateBlobName

func GenerateBlobName(testName string) string

func GenerateBlockIDsList

func GenerateBlockIDsList(count int) []string

func GenerateContainerName

func GenerateContainerName(testName string) string

func GenerateData

func GenerateData(sizeInBytes int) (io.ReadSeekCloser, []byte)

func GenerateEntityName

func GenerateEntityName(testName string) string

func GenerateName

func GenerateName(prefix string) string

This function generates an entity name by concatenating the passed prefix, the name of the test requesting the entity name, and the minute, second, and nanoseconds of the call. This should make it easy to associate the entities with their test, uniquely identify them, and determine the order in which they were created. Note that this imposes a restriction on the length of test names

func GetAccountSAS added in v1.1.0

func GetAccountSAS(permissions sas.AccountPermissions, resourceTypes sas.AccountResourceTypes) (string, error)

func GetAppendBlobClient added in v1.2.0

func GetAppendBlobClient(appendBlobName string, containerClient *container.Client) *appendblob.Client

func GetBlobClient

func GetBlobClient(blockBlobName string, containerClient *container.Client) *blob.Client

func GetBlockBlobClient

func GetBlockBlobClient(blockBlobName string, containerClient *container.Client) *blockblob.Client

func GetCPKScopeInfo

func GetCPKScopeInfo(t *testing.T) blob.CPKScopeInfo

func GetClient

func GetClient(t *testing.T, accountType TestAccountType, options *azblob.ClientOptions) (*azblob.Client, error)

func GetContainerClient

func GetContainerClient(containerName string, s *service.Client) *container.Client

func GetDataAndReader added in v1.1.0

func GetDataAndReader(testName string, n int) (*bytes.Reader, []byte)

func GetGenericAccountInfo added in v1.1.0

func GetGenericAccountInfo(accountType TestAccountType) (string, string)

func GetGenericConnectionString added in v1.1.0

func GetGenericConnectionString(accountType TestAccountType) (*string, error)

func GetGenericSharedKeyCredential added in v1.1.0

func GetGenericSharedKeyCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error)

func GetGenericTokenCredential added in v1.1.0

func GetGenericTokenCredential() (azcore.TokenCredential, error)

func GetReaderToGeneratedBytes

func GetReaderToGeneratedBytes(n int) io.ReadSeekCloser

func GetRelativeTimeFromAnchor

func GetRelativeTimeFromAnchor(anchorTime *time.Time, amount time.Duration) time.Time

func GetRelativeTimeGMT

func GetRelativeTimeGMT(amount time.Duration) time.Time

func GetRequiredEnv

func GetRequiredEnv(name string) (string, error)

GetRequiredEnv gets an environment variable by name and returns an error if it is not found

func GetServiceClient

func GetServiceClient(t *testing.T, accountType TestAccountType, options *service.ClientOptions) (*service.Client, error)

func GetServiceClientFromConnectionString

func GetServiceClientFromConnectionString(t *testing.T, accountType TestAccountType, options *service.ClientOptions) (*service.Client, error)

func GetServiceClientNoCredential added in v1.1.0

func GetServiceClientNoCredential(t *testing.T, sasUrl string, options *service.ClientOptions) (*service.Client, error)

func GetServiceSAS added in v1.1.0

func GetServiceSAS(containerName string, permissions sas.BlobPermissions) (string, error)

func GetUserDelegationSAS added in v1.1.0

func GetUserDelegationSAS(svcClient *service.Client, containerName string, permissions sas.BlobPermissions) (string, error)

func ListBlobsCount added in v0.6.0

func ListBlobsCount(ctx context.Context, _require *require.Assertions, listPager *runtime.Pager[container.ListBlobsFlatResponse], ctr int)

func RunTestRequiringServiceProperties

func RunTestRequiringServiceProperties(ctx context.Context, _require *require.Assertions, svcClient *service.Client, code string,
	enableServicePropertyFunc func(context.Context, *require.Assertions, *service.Client),
	testImplFunc func(context.Context, *require.Assertions, *service.Client) error,
	disableServicePropertyFunc func(context.Context, *require.Assertions, *service.Client))

Some tests require setting service properties. It can take up to 30 seconds for the new properties to be reflected across all FEs. We will enable the necessary property and try to run the test implementation. If it fails with an error that should be due to those changes not being reflected yet, we will wait 30 seconds and try the test again. If it fails this time for any reason, we fail the test. It is the responsibility of the testImplFunc to determine which error string indicates the test should be retried. There can only be one such string. All errors that cannot be due to this detail should be asserted and not returned as an error string.

func SetClientOptions added in v1.1.0

func SetClientOptions(t *testing.T, opts *azcore.ClientOptions)

func SetupSuite added in v1.2.1

func SetupSuite(suite *suite.Suite) *recording.TestProxyInstance

func TearDownSuite added in v1.2.1

func TearDownSuite(suite *suite.Suite, proxy *recording.TestProxyInstance)

func ValidateBlobErrorCode

func ValidateBlobErrorCode(_require *require.Assertions, err error, code bloberror.Code)

func ValidateHTTPErrorCode

func ValidateHTTPErrorCode(_require *require.Assertions, err error, code int)

func ValidateUpload

func ValidateUpload(ctx context.Context, _require *require.Assertions, blobClient *blockblob.Client)

Types

type FakeCredential added in v1.1.0

type FakeCredential struct {
}

func (*FakeCredential) GetToken added in v1.1.0

type TestAccountType

type TestAccountType string
const (
	TestAccountDefault    TestAccountType = ""
	TestAccountSecondary  TestAccountType = "SECONDARY_"
	TestAccountPremium    TestAccountType = "PREMIUM_"
	TestAccountSoftDelete TestAccountType = "SOFT_DELETE_"
	TestAccountDatalake   TestAccountType = "DATALAKE_"
	TestAccountImmutable  TestAccountType = "IMMUTABLE_"
)

Jump to

Keyboard shortcuts

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