From a61980ef21343a77488743029bceb6aaac875462 Mon Sep 17 00:00:00 2001 From: tanyasethi-msft <124860586+tanyasethi-msft@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:44:15 +0530 Subject: [PATCH] [AzDatalake] Set Expiry (#22170) * corrected release date in changelog * setExpiry for files * lint error * recordings --- sdk/storage/azdatalake/assets.json | 2 +- sdk/storage/azdatalake/file/client_test.go | 79 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/sdk/storage/azdatalake/assets.json b/sdk/storage/azdatalake/assets.json index a3472b483893..cb3cf3946254 100644 --- a/sdk/storage/azdatalake/assets.json +++ b/sdk/storage/azdatalake/assets.json @@ -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" } \ No newline at end of file diff --git a/sdk/storage/azdatalake/file/client_test.go b/sdk/storage/azdatalake/file/client_test.go index 33794a13a3ba..9508fb1f5e7b 100644 --- a/sdk/storage/azdatalake/file/client_test.go +++ b/sdk/storage/azdatalake/file/client_test.go @@ -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()