Documentation ¶
Overview ¶
Contains common helpers for TESTS ONLY
Contains common helpers for TESTS ONLY ¶
Contains common helpers for TESTS ONLY
Index ¶
- Constants
- Variables
- func AfterTest(t *testing.T, suite string, test string)
- func BeforeTest(t *testing.T, suite string, test string)
- func BlobListToMap(list []string) map[string]bool
- func BlockIDIntToBase64(blockID int) string
- func CreateNewAppendBlob(ctx context.Context, _require *require.Assertions, appendBlobName string, ...) *appendblob.Client
- func CreateNewBlobs(ctx context.Context, _require *require.Assertions, blobNames []string, ...)
- func CreateNewBlobsListTier(ctx context.Context, _require *require.Assertions, blobNames []string, ...)
- func CreateNewBlockBlob(ctx context.Context, _require *require.Assertions, blockBlobName string, ...) *blockblob.Client
- func CreateNewBlockBlobWithCPK(ctx context.Context, _require *require.Assertions, blockBlobName string, ...) (bbClient *blockblob.Client)
- func CreateNewContainer(ctx context.Context, _require *require.Assertions, containerName string, ...) *container.Client
- func DeleteContainer(ctx context.Context, _require *require.Assertions, ...)
- func DeleteContainerUsingManagementClient(_require *require.Assertions, accountType TestAccountType, ...)
- func DisableSoftDelete(ctx context.Context, _require *require.Assertions, client *service.Client)
- func EnableSoftDelete(ctx context.Context, _require *require.Assertions, client *service.Client)
- func GenerateBlobName(testName string) string
- func GenerateBlockIDsList(count int) []string
- func GenerateContainerName(testName string) string
- func GenerateData(sizeInBytes int) (io.ReadSeekCloser, []byte)
- func GenerateEntityName(testName string) string
- func GenerateName(prefix string) string
- func GetAccountSAS(permissions sas.AccountPermissions, resourceTypes sas.AccountResourceTypes) (string, error)
- func GetAppendBlobClient(appendBlobName string, containerClient *container.Client) *appendblob.Client
- func GetBlobClient(blockBlobName string, containerClient *container.Client) *blob.Client
- func GetBlockBlobClient(blockBlobName string, containerClient *container.Client) *blockblob.Client
- func GetCPKScopeInfo(t *testing.T) blob.CPKScopeInfo
- func GetClient(t *testing.T, accountType TestAccountType, options *azblob.ClientOptions) (*azblob.Client, error)
- func GetContainerClient(containerName string, s *service.Client) *container.Client
- func GetDataAndReader(testName string, n int) (*bytes.Reader, []byte)
- func GetGenericAccountInfo(accountType TestAccountType) (string, string)
- func GetGenericConnectionString(accountType TestAccountType) (*string, error)
- func GetGenericSharedKeyCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error)
- func GetGenericTokenCredential() (azcore.TokenCredential, error)
- func GetReaderToGeneratedBytes(n int) io.ReadSeekCloser
- func GetRelativeTimeFromAnchor(anchorTime *time.Time, amount time.Duration) time.Time
- func GetRelativeTimeGMT(amount time.Duration) time.Time
- func GetRequiredEnv(name string) (string, error)
- func GetServiceClient(t *testing.T, accountType TestAccountType, options *service.ClientOptions) (*service.Client, error)
- func GetServiceClientFromConnectionString(t *testing.T, accountType TestAccountType, options *service.ClientOptions) (*service.Client, error)
- func GetServiceClientNoCredential(t *testing.T, sasUrl string, options *service.ClientOptions) (*service.Client, error)
- func GetServiceSAS(containerName string, permissions sas.BlobPermissions) (string, error)
- func GetUserDelegationSAS(svcClient *service.Client, containerName string, ...) (string, error)
- func ListBlobsCount(ctx context.Context, _require *require.Assertions, ...)
- func RunTestRequiringServiceProperties(ctx context.Context, _require *require.Assertions, svcClient *service.Client, ...)
- func SetClientOptions(t *testing.T, opts *azcore.ClientOptions)
- func SetupSuite(suite *suite.Suite) *recording.TestProxyInstance
- func TearDownSuite(suite *suite.Suite, proxy *recording.TestProxyInstance)
- func ValidateBlobErrorCode(_require *require.Assertions, err error, code bloberror.Code)
- func ValidateHTTPErrorCode(_require *require.Assertions, err error, code int)
- func ValidateUpload(ctx context.Context, _require *require.Assertions, ...)
- type TestAccountType
Constants ¶
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" )
const ( FakeStorageAccount = "fakestorage" FakeStorageURL = "https://fakestorage.blob.core.windows.net" FakeToken = "faketoken" )
const ( RecordingDirectory = "sdk/storage/azblob/testdata" ContainerPrefix = "goc" BlobPrefix = "gotestblob" BlockBlobDefaultData = "GoBlockBlobData" InvalidHeaderErrorSubstring = "invalid header field" // error thrown by the http client )
const (
EncryptionScopeEnvVar = "AZURE_STORAGE_ENCRYPTION_SCOPE"
)
Variables ¶
var ( BlobContentType = "my_type" BlobContentDisposition = "my_disposition" BlobCacheControl = "control" BlobContentLanguage = "my_language" BlobContentEncoding = "my_encoding" )
var BasicBlobTagsMap = map[string]string{
"azure": "blob",
"blob": "sdk",
"sdk": "go",
}
var BasicHeaders = blob.HTTPHeaders{ BlobContentType: &BlobContentType, BlobContentDisposition: &BlobContentDisposition, BlobCacheControl: &BlobCacheControl, BlobContentMD5: nil, BlobContentLanguage: &BlobContentLanguage, BlobContentEncoding: &BlobContentEncoding, }
var BasicMetadata = map[string]*string{"Foo": to.Ptr("bar")}
var SpecialCharBlobTagsMap = map[string]string{
"+-./:=_ ": "firsttag",
"tag2": "+-./:=_",
"+-./:=_1": "+-./:=_",
"Microsoft Azure": "Azure Storage",
"Storage+SDK": "SDK/GO",
"GO ": ".Net",
}
var TestCPKByValue = blob.CPKInfo{
EncryptionKey: &testEncryptedKey,
EncryptionKeySHA256: &testEncryptedHash,
EncryptionAlgorithm: &testEncryptionAlgorithm,
}
var TestInvalidCPKByScope = blob.CPKScopeInfo{
EncryptionScope: &testInvalidEncryptedScope,
}
var TestInvalidCPKByValue = blob.CPKInfo{
EncryptionKey: &testInvalidEncryptedKey,
EncryptionKeySHA256: &testInvalidEncryptedHash,
EncryptionAlgorithm: &testEncryptionAlgorithm,
}
Functions ¶
func BlobListToMap ¶
func BlockIDIntToBase64 ¶
BlockIDIntToBase64 functions convert an int block ID to a base-64 string and vice versa
func CreateNewAppendBlob ¶
func CreateNewAppendBlob(ctx context.Context, _require *require.Assertions, appendBlobName string, containerClient *container.Client) *appendblob.Client
func CreateNewBlobs ¶
func CreateNewBlobsListTier ¶
func CreateNewBlobsListTier(ctx context.Context, _require *require.Assertions, blobNames []string, containerClient *container.Client, tier *blob.AccessTier)
func CreateNewBlockBlob ¶
func CreateNewContainer ¶
func DeleteContainer ¶
func DeleteContainerUsingManagementClient ¶
func DeleteContainerUsingManagementClient(_require *require.Assertions, accountType TestAccountType, containerName string)
func DisableSoftDelete ¶
func EnableSoftDelete ¶
func GenerateBlobName ¶
func GenerateBlockIDsList ¶
func GenerateContainerName ¶
func GenerateData ¶
func GenerateData(sizeInBytes int) (io.ReadSeekCloser, []byte)
func GenerateEntityName ¶
func GenerateName ¶
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 ¶
func GetAccountSAS(permissions sas.AccountPermissions, resourceTypes sas.AccountResourceTypes) (string, error)
func GetAppendBlobClient ¶
func GetAppendBlobClient(appendBlobName string, containerClient *container.Client) *appendblob.Client
func GetBlobClient ¶
func GetBlockBlobClient ¶
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 GetGenericAccountInfo ¶
func GetGenericAccountInfo(accountType TestAccountType) (string, string)
func GetGenericConnectionString ¶
func GetGenericConnectionString(accountType TestAccountType) (*string, error)
func GetGenericSharedKeyCredential ¶
func GetGenericSharedKeyCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error)
func GetGenericTokenCredential ¶
func GetGenericTokenCredential() (azcore.TokenCredential, error)
func GetReaderToGeneratedBytes ¶
func GetReaderToGeneratedBytes(n int) io.ReadSeekCloser
func GetRequiredEnv ¶
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 GetServiceSAS ¶
func GetServiceSAS(containerName string, permissions sas.BlobPermissions) (string, error)
func GetUserDelegationSAS ¶
func ListBlobsCount ¶
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 ¶
func SetClientOptions(t *testing.T, opts *azcore.ClientOptions)
func SetupSuite ¶
func SetupSuite(suite *suite.Suite) *recording.TestProxyInstance
func TearDownSuite ¶
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 ¶
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_" )