Skip to content

Commit

Permalink
Migrated some blob tests to new e2e test framework (#2736)
Browse files Browse the repository at this point in the history
* Migrated smoke tests for auto detect blob type
  • Loading branch information
gapra-msft authored Jul 25, 2024
1 parent ae2fa21 commit 0254a7e
Show file tree
Hide file tree
Showing 24 changed files with 864 additions and 743 deletions.
7 changes: 7 additions & 0 deletions e2etest/newe2e_account_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func DeleteAccount(a Asserter, arm AccountResourceManager) {
const (
PrimaryStandardAcct string = "PrimaryStandard"
PrimaryHNSAcct string = "PrimaryHNS"
PremiumPageBlobAcct string = "PremiumPageBlob"
)

func AccountRegistryInitHook(a Asserter) {
Expand All @@ -140,10 +141,16 @@ func AccountRegistryInitHook(a Asserter) {
accountKey: acctInfo.HNS.AccountKey,
accountType: EAccountType.HierarchicalNamespaceEnabled(),
}
AccountRegistry[PremiumPageBlobAcct] = &AzureAccountResourceManager{
accountName: acctInfo.PremiumPage.AccountName,
accountKey: acctInfo.PremiumPage.AccountKey,
accountType: EAccountType.PremiumPageBlobs(),
}
} else {
// Create standard accounts
AccountRegistry[PrimaryStandardAcct] = CreateAccount(a, EAccountType.Standard(), nil)
AccountRegistry[PrimaryHNSAcct] = CreateAccount(a, EAccountType.HierarchicalNamespaceEnabled(), nil)
AccountRegistry[PremiumPageBlobAcct] = CreateAccount(a, EAccountType.PremiumPageBlobs(), nil)
}
}

Expand Down
4 changes: 4 additions & 0 deletions e2etest/newe2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type NewE2EConfig struct {
AccountName string `env:"NEW_E2E_HNS_ACCOUNT_NAME,required"`
AccountKey string `env:"NEW_E2E_HNS_ACCOUNT_KEY,required"`
} `env:",required"`
PremiumPage struct {
AccountName string `env:"NEW_E2E_PREMIUM_PAGE_ACCOUNT_NAME,required"`
AccountKey string `env:"NEW_E2E_PREMIUM_PAGE_ACCOUNT_KEY,required"`
} `env:",required"`
} `env:",required,minimum_required=1"`
} `env:",required,mutually_exclusive"`

Expand Down
15 changes: 15 additions & 0 deletions e2etest/newe2e_resource_manager_azstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@ import (
filesas "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
fileservice "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
"github.com/Azure/azure-storage-azcopy/v10/common"
"strings"
)

func addWildCard(uri string, optList ...GetURIOptions) string {
wildcard := FirstOrZero(optList).Wildcard
if wildcard == "" {
return uri
}
if strings.Contains(uri, "?") {
uri = strings.Replace(uri, "?", wildcard+"?", 1)
} else {
uri += wildcard
}

return uri
}

type AzureAccountResourceManager struct {
accountName string
accountKey string
Expand Down
5 changes: 4 additions & 1 deletion e2etest/newe2e_resource_manager_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
type GetURIOptions struct {
RemoteOpts RemoteURIOpts
AzureOpts AzureURIOpts
// The wildcard string to append to the end of a resource URI.
Wildcard string
}

type RemoteURIOpts struct {
Expand Down Expand Up @@ -76,7 +78,7 @@ func TryApplySpecificAuthType(rm ResourceManager, cred ExplicitCredentialTypes,
return rrm.WithSpecificAuthType(cred, a, opts...)
}

return CreateAzCopyTarget(rm, EExplicitCredentialType.None(), a)
return CreateAzCopyTarget(rm, EExplicitCredentialType.None(), a, opts...)
}

// ExplicitCredentialTypes defines a more explicit enum for credential types as AzCopy's internal definition is very loose (e.g. Anonymous can be public or SAS); accepts the URI as-is.
Expand Down Expand Up @@ -301,6 +303,7 @@ type FileProperties struct {
FileCreationTime *time.Time
FileLastWriteTime *time.Time
FilePermissions *string
LastModifiedTime *time.Time
}

func (f FileProperties) hasCustomTimes() bool {
Expand Down
6 changes: 6 additions & 0 deletions e2etest/newe2e_resource_managers_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (b *BlobServiceResourceManager) ListContainers(a Asserter) []string {
func (b *BlobServiceResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -348,6 +349,7 @@ func (b *BlobContainerResourceManager) Level() cmd.LocationLevel {
func (b *BlobContainerResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -658,6 +660,9 @@ func (b *BlobObjectResourceManager) GetPropertiesWithOptions(a Asserter, options
Type: resp.BlobType,
Tags: func() map[string]string {
out := make(map[string]string)
if b.internalAccount.AccountType() == EAccountType.PremiumPageBlobs() {
return out
}
resp, err := b.internalClient.GetTags(ctx, nil)
a.NoError("Get tags", err)
for _, tag := range resp.BlobTagSet {
Expand Down Expand Up @@ -721,6 +726,7 @@ func (b *BlobObjectResourceManager) Level() cmd.LocationLevel {
func (b *BlobObjectResourceManager) URI(opts ...GetURIOptions) string {
base := blobStripSAS(b.internalClient.URL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down
3 changes: 3 additions & 0 deletions e2etest/newe2e_resource_managers_blobfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (b *BlobFSServiceResourceManager) Level() cmd.LocationLevel {
func (b *BlobFSServiceResourceManager) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.internalClient.DFSURL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -178,6 +179,7 @@ func (b *BlobFSFileSystemResourceManager) Level() cmd.LocationLevel {
func (b *BlobFSFileSystemResourceManager) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.internalClient.DFSURL())
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -312,6 +314,7 @@ func (b *BlobFSPathResourceProvider) Level() cmd.LocationLevel {
func (b *BlobFSPathResourceProvider) URI(opts ...GetURIOptions) string {
base := dfsStripSAS(b.getFileClient().DFSURL()) // obj type doesn't matter here, URL is the same under the hood
base = b.internalAccount.ApplySAS(base, b.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down
7 changes: 7 additions & 0 deletions e2etest/newe2e_resource_managers_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (s *FileServiceResourceManager) Level() cmd.LocationLevel {
func (s *FileServiceResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(s.internalClient.URL())
base = s.internalAccount.ApplySAS(base, s.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -181,6 +182,7 @@ func (s *FileShareResourceManager) Level() cmd.LocationLevel {
func (s *FileShareResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(s.internalClient.URL())
base = s.internalAccount.ApplySAS(base, s.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -288,6 +290,7 @@ func (s *FileShareResourceManager) ListObjects(a Asserter, targetDir string, rec
FileCreationTime: v.Properties.CreationTime,
FileLastWriteTime: v.Properties.LastWriteTime,
FilePermissions: permissions,
LastModifiedTime: v.Properties.LastModified,
},
}
}
Expand Down Expand Up @@ -324,6 +327,7 @@ func (s *FileShareResourceManager) ListObjects(a Asserter, targetDir string, rec
FileCreationTime: v.Properties.CreationTime,
FileLastWriteTime: v.Properties.LastWriteTime,
FilePermissions: permissions,
LastModifiedTime: v.Properties.LastModified,
},
}
}
Expand Down Expand Up @@ -398,6 +402,7 @@ func (f *FileObjectResourceManager) Level() cmd.LocationLevel {
func (f *FileObjectResourceManager) URI(opts ...GetURIOptions) string {
base := fileStripSAS(f.getFileClient().URL()) // restype doesn't matter here, same URL under the hood
base = f.internalAccount.ApplySAS(base, f.Location(), opts...)
base = addWildCard(base, opts...)

return base
}
Expand Down Expand Up @@ -546,6 +551,7 @@ func (f *FileObjectResourceManager) GetProperties(a Asserter) (out ObjectPropert
FileCreationTime: resp.FileCreationTime,
FileLastWriteTime: resp.FileLastWriteTime,
FilePermissions: permissions,
LastModifiedTime: resp.LastModified,
},
}
case common.EEntityType.File():
Expand Down Expand Up @@ -577,6 +583,7 @@ func (f *FileObjectResourceManager) GetProperties(a Asserter) (out ObjectPropert
FileCreationTime: resp.FileCreationTime,
FileLastWriteTime: resp.FileLastWriteTime,
FilePermissions: permissions,
LastModifiedTime: resp.LastModified,
},
}
default:
Expand Down
18 changes: 10 additions & 8 deletions e2etest/newe2e_resource_managers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (l *LocalContainerResourceManager) Level() cmd.LocationLevel {
}

func (l *LocalContainerResourceManager) URI(opts ...GetURIOptions) string {
return l.RootPath
base := l.RootPath
base = addWildCard(base, opts...)
return base
}

func (l *LocalContainerResourceManager) Parent() ResourceManager {
Expand Down Expand Up @@ -217,7 +219,9 @@ func (l *LocalObjectResourceManager) Level() cmd.LocationLevel {
}

func (l *LocalObjectResourceManager) URI(opts ...GetURIOptions) string {
return filepath.Join(l.container.RootPath, l.objectPath)
base := filepath.Join(l.container.RootPath, l.objectPath)
base = addWildCard(base, opts...)
return base
}

func (l *LocalObjectResourceManager) Parent() ResourceManager {
Expand Down Expand Up @@ -311,12 +315,10 @@ func (l *LocalObjectResourceManager) GetProperties(a Asserter) ObjectProperties

perms := smb.GetSDDL(a)

out.FileProperties = FileProperties{
FileAttributes: PtrOf(attr.String()),
FileCreationTime: PtrOf(props.FileCreationTime()),
FileLastWriteTime: PtrOf(props.FileLastWriteTime()),
FilePermissions: common.Iff(perms == "", nil, &perms),
}
out.FileProperties.FileAttributes = PtrOf(attr.String())
out.FileProperties.FileCreationTime = PtrOf(props.FileCreationTime())
out.FileProperties.FileLastWriteTime = PtrOf(props.FileLastWriteTime())
out.FileProperties.FilePermissions = common.Iff(perms == "", nil, &perms)
}

return out
Expand Down
9 changes: 6 additions & 3 deletions e2etest/newe2e_task_runazcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type CreateAzCopyTargetOptions struct {
// SASTokenOptions expects a GenericSignatureValues, which can contain account signatures, or a service signature.
SASTokenOptions GenericSignatureValues
Scheme string
// The wildcard string to append to the end of a resource URI.
Wildcard string
}

func CreateAzCopyTarget(rm ResourceManager, authType ExplicitCredentialTypes, a Asserter, opts ...CreateAzCopyTargetOptions) AzCopyTarget {
Expand Down Expand Up @@ -161,6 +163,7 @@ func (c *AzCopyCommand) applyTargetAuth(a Asserter, target ResourceManager) stri

opts.AzureOpts.SASValues = tgt.Opts.SASTokenOptions
opts.RemoteOpts.Scheme = tgt.Opts.Scheme
opts.Wildcard = tgt.Opts.Wildcard
} else if target.Location() == common.ELocation.S3() {
intendedAuthType = EExplicitCredentialType.S3()
} else if target.Location() == common.ELocation.GCP() {
Expand All @@ -169,7 +172,7 @@ func (c *AzCopyCommand) applyTargetAuth(a Asserter, target ResourceManager) stri

switch intendedAuthType {
case EExplicitCredentialType.PublicAuth(), EExplicitCredentialType.None():
return target.URI() // no SAS, no nothing.
return target.URI(opts) // no SAS, no nothing.
case EExplicitCredentialType.SASToken():
opts.AzureOpts.WithSAS = true
return target.URI(opts)
Expand Down Expand Up @@ -224,10 +227,10 @@ func (c *AzCopyCommand) applyTargetAuth(a Asserter, target ResourceManager) stri
}
}

return target.URI() // Generate like public
return target.URI(opts) // Generate like public
default:
a.Error("unsupported credential type")
return target.URI()
return target.URI(opts)
}
}

Expand Down
1 change: 1 addition & 0 deletions e2etest/newe2e_task_runazcopy_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ type CopySyncCommonFlags struct {
TrailingDot *common.TrailingDotOption `flag:"trailing-dot"`
CPKByName *string `flag:"cpk-by-name"`
CPKByValue *bool `flag:"cpk-by-value"`
IncludePattern *string `flag:"include-pattern"`
}

// CopyFlags is a more exclusive struct including flags exclusi
Expand Down
File renamed without changes.
Loading

0 comments on commit 0254a7e

Please sign in to comment.