Skip to content

Commit

Permalink
Added VersionId alias and integration tests for both alias and parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
sankettangade committed Jan 31, 2025
1 parent b3c8bf3 commit 0d03b90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class ReadS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
/// <summary>
/// If specified, the specific version of the S3 object is returned.
/// </summary>
[Alias("VersionId")]
[Parameter(Position = 3, ParameterSetName = ParamSet_ToLocalFile, ValueFromPipelineByPropertyName = true)]
public System.String Version { get; set; }
#endregion
Expand Down
22 changes: 21 additions & 1 deletion tests/S3/S3.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ Describe -Tag "Smoke" "S3" {
BeforeAll {
$script:bucketName = "pstest-" + [DateTime]::Now.ToFileTime()
New-S3Bucket -BucketName $script:bucketName


$key = "versionTest"
$void = New-Item -Path temp\bar -Type directory -Force
$void = New-Item -Path temp\bar\baz -Type directory -Force

Expand All @@ -85,6 +86,13 @@ Describe -Tag "Smoke" "S3" {
Write-S3Object -BucketName $script:bucketName -KeyPrefix bar2\ -Folder .\temp\bar -Recurse
Write-S3Object -BucketName $script:bucketName -Key bar2\foo.txt -Content "foo"
Write-S3Object -BucketName $script:bucketName -Key basic.txt -File "temp\basic.txt"

Write-S3BucketVersioning -BucketName $script:bucketName -VersioningConfig_Status Enabled

Write-S3Object -BucketName $script:bucketName -Key $key -Content "Version 1"
Write-S3Object -BucketName $script:bucketName -Key $key -Content "Version 2"

$s3ObjectVersions = Get-S3Version -BucketName $script:bucketName -Prefix $key
}

AfterAll {
Expand Down Expand Up @@ -129,6 +137,18 @@ Describe -Tag "Smoke" "S3" {
Read-S3Object -BucketName $script:bucketName -Key "basic.txt" -File "temp\basic2.txt"
(Get-Content "temp\basic2.txt").Length | Should -BeGreaterThan 0
}

It "Can retrieve a specific version using the VersionId alias" {
$versionId = $s3ObjectVersions.Versions[0].VersionId
Read-S3Object -BucketName $script:bucketName -Key $key -VersionId $versionId -File "temp\version-test.txt"
(Get-Content "temp\version-test.txt") | Should -Be "Version 2"
}

It "Can retrieve a specific version using the Version parameter" {
$versionId = $s3ObjectVersions.Versions[1].VersionId
Read-S3Object -BucketName $script:bucketName -Key $key -Version $versionId -File "temp\version-test.txt"
(Get-Content "temp\version-test.txt") | Should -Be "Version 1"
}
}

Context "Copying" {
Expand Down

0 comments on commit 0d03b90

Please sign in to comment.