Skip to content

Commit

Permalink
[AzDatalake] Set Expiry (#22170)
Browse files Browse the repository at this point in the history
* corrected release date in changelog

* setExpiry for files

* lint error

* recordings
  • Loading branch information
tanyasethi-msft committed Jan 2, 2024
1 parent 9237c17 commit a61980e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/storage/azdatalake/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azdatalake",
"Tag": "go/storage/azdatalake_36b1978c0d"
"Tag": "go/storage/azdatalake_c883370a69"
}
79 changes: 79 additions & 0 deletions sdk/storage/azdatalake/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,85 @@ func (s *RecordedTestSuite) TestDeleteFileIfETagMatchFalse() {
testcommon.ValidateErrorCode(_require, err, datalakeerror.ConditionNotMet)
}

func (s *RecordedTestSuite) TestFileSetExpiry() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

fileName := testcommon.GenerateFileName(testName)
fClient, err := testcommon.GetFileClient(filesystemName, fileName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

resp, err := fClient.Create(context.Background(), nil)
_require.NoError(err)
_require.NotNil(resp)

_, err = fClient.SetExpiry(context.Background(), file.SetExpiryValues{ExpiryType: file.SetExpiryTypeNeverExpire}, nil)
_require.NoError(err)

res, err := fClient.GetProperties(context.Background(), nil)
_require.Nil(res.ExpiresOn)
_require.NoError(err)

_, err = fClient.SetExpiry(
context.Background(),
file.SetExpiryValues{
ExpiryType: file.SetExpiryTypeRelativeToCreation,
ExpiresOn: strconv.Itoa(10),
},
nil,
)
_require.NoError(err)

time.Sleep(time.Second * 12)

_, err = fClient.GetProperties(context.Background(), nil)
testcommon.ValidateErrorCode(_require, err, datalakeerror.PathNotFound)
}

func (s *UnrecordedTestSuite) TestFileSetExpiryTypeAbsoluteTime() {
_require := require.New(s.T())
testName := s.T().Name()

filesystemName := testcommon.GenerateFileSystemName(testName)
fsClient, err := testcommon.GetFileSystemClient(filesystemName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)
defer testcommon.DeleteFileSystem(context.Background(), _require, fsClient)

_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

fileName := testcommon.GenerateFileName(testName)
fClient, err := testcommon.GetFileClient(filesystemName, fileName, s.T(), testcommon.TestAccountDatalake, nil)
_require.NoError(err)

resp, err := fClient.Create(context.Background(), nil)
_require.NoError(err)
_require.NotNil(resp)

_, err = fClient.SetExpiry(
context.Background(),
file.SetExpiryValues{
ExpiryType: file.SetExpiryTypeAbsolute,
ExpiresOn: time.Now().Add(5 * time.Second).UTC().Format(http.TimeFormat),
},
nil)
_require.NoError(err)

time.Sleep(time.Second * 7)

_, err = fClient.GetProperties(context.Background(), nil)
testcommon.ValidateErrorCode(_require, err, datalakeerror.PathNotFound)

}

func (s *RecordedTestSuite) TestFileSetAccessControlNil() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down

0 comments on commit a61980e

Please sign in to comment.