Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a few service client tests #19924

Merged
merged 10 commits into from
Feb 10, 2023
8 changes: 4 additions & 4 deletions sdk/storage/azblob/appendblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockFromURL() {
// Get source abClient URL with SAS for AppendBlockFromURL.
srcBlobParts, _ := blob.ParseURL(srcBlob.URL())

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)
perms := sas.BlobPermissions{Read: true}

Expand Down Expand Up @@ -345,7 +345,7 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockFromURLWithMD5() {
// Get source abClient URL with SAS for AppendBlockFromURL.
srcBlobParts, _ := blob.ParseURL(srcBlob.URL())

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)
perms := sas.BlobPermissions{Read: true}

Expand Down Expand Up @@ -1763,7 +1763,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockPermanentDelete() {
parts, err := sas.ParseURL(abClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS and set Permanent Delete to true
Expand Down Expand Up @@ -1872,7 +1872,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlockPermanentDeleteWithoutPerm
parts, err := sas.ParseURL(abClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS
Expand Down
10 changes: 5 additions & 5 deletions sdk/storage/azblob/blob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *BlobUnrecordedTestsSuite) TestCreateBlobClientWithSnapshotAndSAS() {
currentTime, err := time.Parse(time.UnixDate, "Fri Jun 11 20:00:00 UTC 2049")
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

sasQueryParams, err := sas.AccountSignatureValues{
Expand Down Expand Up @@ -152,7 +152,7 @@ func (s *BlobUnrecordedTestsSuite) TestCreateBlobClientWithSnapshotAndSASUsingCo
currentTime, err := time.Parse(time.UnixDate, "Fri Jun 11 20:00:00 UTC 2049")
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)
sasQueryParams, err := sas.AccountSignatureValues{
Protocol: sas.ProtocolHTTPS,
Expand Down Expand Up @@ -418,7 +418,7 @@ func (s *BlobRecordedTestsSuite) TestBlobStartCopySourcePrivate() {
// bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
//
// // Create sas values for the source blob
// credential, err := testcommon.GetGenericCredential(nil, testcommon.TestAccountDefault)
// credential, err := testcommon.GetGenericSharedKeyCredential(nil, testcommon.TestAccountDefault)
// if err != nil {
// s.T().Fatal("Couldn't fetch credential because " + err.Error())
// }
Expand Down Expand Up @@ -3022,7 +3022,7 @@ func (s *BlobRecordedTestsSuite) TestPermanentDelete() {
parts, err := sas.ParseURL(bbClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS and set Permanent Delete to true
Expand Down Expand Up @@ -3132,7 +3132,7 @@ func (s *BlobRecordedTestsSuite) TestPermanentDeleteWithoutPermission() {
parts, err := sas.ParseURL(bbClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS
Expand Down
10 changes: 5 additions & 5 deletions sdk/storage/azblob/blockblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type BlockBlobUnrecordedTestsSuite struct {
// // Get source blob url with SAS for StageFromURL.
// srcBlobParts, _ := NewBlobURLParts(srcBlob.URL())
//
// credential, err := testcommon.GetGenericCredential(nil, testcommon.TestAccountDefault)
// credential, err := testcommon.GetGenericSharedKeyCredential(nil, testcommon.TestAccountDefault)
// _require.Nil(err)
//
// srcBlobParts.SAS, err = BlobSASSignatureValues{
Expand Down Expand Up @@ -287,7 +287,7 @@ type BlockBlobUnrecordedTestsSuite struct {
// // Get source blob url with SAS for StageFromURL.
// srcBlobParts, _ := NewBlobURLParts(srcBlob.URL())
//
// credential, err := testcommon.GetGenericCredential(nil, testcommon.TestAccountDefault)
// credential, err := testcommon.GetGenericSharedKeyCredential(nil, testcommon.TestAccountDefault)
// _require.Nil(err)
//
// srcBlobParts.SAS, err = BlobSASSignatureValues{
Expand Down Expand Up @@ -387,7 +387,7 @@ type BlockBlobUnrecordedTestsSuite struct {
// contentLanguageVal := "content-language-override"
// contentTypeVal := "content-type-override"
//
// credential, err := testcommon.GetGenericCredential(nil, testcommon.TestAccountDefault)
// credential, err := testcommon.GetGenericSharedKeyCredential(nil, testcommon.TestAccountDefault)
// _require.Nil(err)
// // Append User Delegation SAS token to URL
// blobParts.SAS, err = BlobSASSignatureValues{
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestSetTierOnCopyBlockBlobFromURL() {
expiryTime, err := time.Parse(time.UnixDate, "Fri Jun 11 20:00:00 UTC 2049")
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
if err != nil {
s.T().Fatal("Couldn't fetch credential because " + err.Error())
}
Expand Down Expand Up @@ -1369,7 +1369,7 @@ func (s *BlockBlobUnrecordedTestsSuite) TestSetTierOnCopyBlockBlobFromURL() {
//
// // Get source blob url with SAS for StageFromURL.
// srcBlobParts, _ := NewBlobURLParts(srcBlob.URL())
// credential, err := testcommon.GetGenericCredential(nil, testcommon.TestAccountDefault)
// credential, err := testcommon.GetGenericSharedKeyCredential(nil, testcommon.TestAccountDefault)
// _require.Nil(err)
// srcBlobParts.SAS, err = blob.SASSignatureValues{
// Protocol: SASProtocolHTTPS, // Users MUST use HTTPS (not HTTP)
Expand Down
36 changes: 19 additions & 17 deletions sdk/storage/azblob/internal/testcommon/clients_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func GetClient(t *testing.T, accountType TestAccountType, options *azblob.Client

setClientOptions(t, &options.ClientOptions)

cred, err := GetGenericCredential(accountType)
cred, err := GetGenericSharedKeyCredential(accountType)
if err != nil {
return nil, err
}
Expand All @@ -118,7 +118,7 @@ func GetServiceClient(t *testing.T, accountType TestAccountType, options *servic

setClientOptions(t, &options.ClientOptions)

cred, err := GetGenericCredential(accountType)
cred, err := GetGenericSharedKeyCredential(accountType)
if err != nil {
return nil, err
}
Expand All @@ -128,48 +128,50 @@ func GetServiceClient(t *testing.T, accountType TestAccountType, options *servic
return serviceClient, err
}

func GetAccountInfo(accountType TestAccountType) (string, string) {
func GetGenericAccountInfo(accountType TestAccountType) (string, string) {
if recording.GetRecordMode() == recording.PlaybackMode {
return FakeStorageAccount, "ZmFrZQ=="
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
}
accountNameEnvVar := string(accountType) + AccountNameEnvVar
accountKeyEnvVar := string(accountType) + AccountKeyEnvVar
accountName, _ := GetRequiredEnv(accountNameEnvVar)
accountKey, _ := GetRequiredEnv(accountKeyEnvVar)
return accountName, accountKey
}

func GetGenericCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error) {
if recording.GetRecordMode() == recording.PlaybackMode {
return azblob.NewSharedKeyCredential(FakeStorageAccount, "ZmFrZQ==")
}

accountName, accountKey := GetAccountInfo(accountType)
func GetGenericSharedKeyCredential(accountType TestAccountType) (*azblob.SharedKeyCredential, error) {
accountName, accountKey := GetGenericAccountInfo(accountType)
if accountName == "" || accountKey == "" {
return nil, errors.New(string(accountType) + AccountNameEnvVar + " and/or " + string(accountType) + AccountKeyEnvVar + " environment variables not specified.")
}
return azblob.NewSharedKeyCredential(accountName, accountKey)
}

func GetConnectionString(accountType TestAccountType) string {
accountName, accountKey := GetAccountInfo(accountType)
func GetGenericConnectionString(accountType TestAccountType) (*string, error) {
accountName, accountKey := GetGenericAccountInfo(accountType)
if accountName == "" || accountKey == "" {
return nil, errors.New(string(accountType) + AccountNameEnvVar + " and/or " + string(accountType) + AccountKeyEnvVar + " environment variables not specified.")
}
connectionString := fmt.Sprintf("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net/",
accountName, accountKey)
return connectionString
return &connectionString, nil
}

func GetServiceClientFromConnectionString(t *testing.T, accountType TestAccountType, options *service.ClientOptions) (*service.Client, error) {
if options == nil {
options = &service.ClientOptions{}
}
setClientOptions(t, &options.ClientOptions)

transport, err := recording.NewRecordingHTTPClient(t, nil)
require.NoError(t, err)
options.Transport = transport

if recording.GetRecordMode() == recording.PlaybackMode {
return service.NewClientWithNoCredential(FakeStorageURL, options)
cred, err := GetGenericConnectionString(accountType)
if err != nil {
return nil, err
}

connectionString := GetConnectionString(accountType)
svcClient, err := service.NewClientFromConnectionString(connectionString, options)
svcClient, err := service.NewClientFromConnectionString(*cred, options)
return svcClient, err
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azblob/pageblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4029,7 +4029,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlockPermanentDelete() {
parts, err := sas.ParseURL(pbClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS and set Permanent Delete to true
Expand Down Expand Up @@ -4146,7 +4146,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageBlockPermanentDeleteWithoutPermissi
parts, err := sas.ParseURL(pbClient.URL()) // Get parts for BlobURL
_require.Nil(err)

credential, err := testcommon.GetGenericCredential(testcommon.TestAccountDefault)
credential, err := testcommon.GetGenericSharedKeyCredential(testcommon.TestAccountDefault)
_require.Nil(err)

// Set Account SAS
Expand Down
Loading