testcommon

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: MIT Imports: 26 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"
)
View Source
const (
	FakeStorageAccount = "fakestorage"
	FakeStorageURL     = "https://fakestorage.blob.core.windows.net"
)
View Source
const (
	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": "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 CreateNewBlobs

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

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 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 GetAccountInfo

func GetAccountInfo(accountType TestAccountType) (string, string)

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 GetConnectionString

func GetConnectionString(accountType TestAccountType) string

func GetContainerClient

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

func GetGenericCredential

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

func GetRandomDataAndReader

func GetRandomDataAndReader(n int) (*bytes.Reader, []byte)

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