package testcommon
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/testcommon"
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 CreateNewBlobs(ctx context.Context, _require *require.Assertions, blobNames []string, containerClient *container.Client)
- func CreateNewBlockBlob(ctx context.Context, _require *require.Assertions, blockBlobName string, containerClient *container.Client) *blockblob.Client
- func CreateNewBlockBlobWithCPK(ctx context.Context, _require *require.Assertions, blockBlobName string, containerClient *container.Client, cpkInfo *blob.CPKInfo, cpkScopeInfo *blob.CPKScopeInfo) (bbClient *blockblob.Client)
- func CreateNewContainer(ctx context.Context, _require *require.Assertions, containerName string, serviceClient *service.Client) *container.Client
- func DeleteContainer(ctx context.Context, _require *require.Assertions, containerClient *container.Client)
- 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 GetAccountInfo(accountType TestAccountType) (string, string)
- 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 GetConnectionString(accountType TestAccountType) string
- func GetContainerClient(containerName string, s *service.Client) *container.Client
- func GetGenericCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error)
- func GetRandomDataAndReader(n int) (*bytes.Reader, []byte)
- 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 ListBlobsCount(ctx context.Context, _require *require.Assertions, listPager *runtime.Pager[container.ListBlobsFlatResponse], ctr int)
- 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))
- 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, blobClient *blockblob.Client)
- 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" )
const ( FakeStorageAccount = "fakestorage" FakeStorageURL = "https://fakestorage.blob.core.windows.net" )
const ( 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 BasicHeaders = blob.HTTPHeaders{ BlobContentType: &BlobContentType, BlobContentDisposition: &BlobContentDisposition, BlobCacheControl: &BlobCacheControl, BlobContentMD5: nil, BlobContentLanguage: &BlobContentLanguage, BlobContentEncoding: &BlobContentEncoding, }
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 AfterTest ¶
func BeforeTest ¶
func BlobListToMap ¶
func BlockIDIntToBase64 ¶
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 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 GetAccountInfo ¶
func GetAccountInfo(accountType TestAccountType) (string, string)
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 GetConnectionString ¶
func GetConnectionString(accountType TestAccountType) string
func GetContainerClient ¶
func GetGenericCredential ¶
func GetGenericCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error)
func GetRandomDataAndReader ¶
func GetReaderToGeneratedBytes ¶
func GetReaderToGeneratedBytes(n int) io.ReadSeekCloser
func GetRelativeTimeFromAnchor ¶
func GetRelativeTimeGMT ¶
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 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 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_" )
Source Files ¶
clients_auth.go common.go cpk.go
- Version
- v1.0.0
- Published
- Feb 7, 2023
- Platform
- windows/amd64
- Imports
- 26 packages
- Last checked
- 1 hour ago –
Tools for package owners.