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

[GitHub] azcopy list with versionids does not show version id #2550

Merged
merged 14 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/zc_traverser_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ func (t *blobTraverser) createStoredObjectForBlob(preprocessor objectMorpher, bl
object.blobSnapshotID = common.IffNotNil(blobInfo.Snapshot, "")
} else if t.includeDeleted && t.includeVersion && blobInfo.VersionID != nil {
object.blobVersionID = common.IffNotNil(blobInfo.VersionID, "")
} else if blobInfo.VersionID != nil {
object.blobVersionID = common.IffNotNil(blobInfo.VersionID, "")
}
return object
}
Expand Down
65 changes: 65 additions & 0 deletions cmd/zt_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"github.com/Azure/azure-storage-azcopy/v10/common"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)

func TestListVersions(t *testing.T) {
a := assert.New(t)
bsc := getSecondaryBlobServiceClient()
// set up the container with single blob with 2 versions
containerClient, containerName := createNewContainer(a, bsc)
defer deleteContainer(a, containerClient)

blobsToInclude := []string{"AzURE2021.jpeg", "sub1/dir2/HELLO-4.txt", "sub1/test/testing.txt"}
scenarioHelper{}.generateBlobsFromList(a, containerClient, blobsToInclude, blockBlobDefaultData)
a.NotNil(containerClient)

// get dictionary/map of blob: version id
versions := make(map[string]string)
for _, blob := range blobsToInclude {
props, err := containerClient.NewBlockBlobClient(blob).GetProperties(ctx, nil)
a.NoError(err)

versions[blob] = *props.VersionID
}

// confirm that container has 3 blobs
pager := containerClient.NewListBlobsFlatPager(nil)
list, err := pager.NextPage(ctx)
a.NoError(err)
a.NotNil(list.Segment.BlobItems)
a.Equal(3, len(list.Segment.BlobItems))

// set up interceptor
mockedRPC := interceptor{}
Rpc = mockedRPC.intercept
mockedRPC.init()

mockedLcm := mockedLifecycleManager{infoLog: make(chan string, 50)}
mockedLcm.SetOutputFormat(common.EOutputFormat.Text()) // text format
glcm = &mockedLcm

// construct the raw input to simulate user input
rawContainerURLWithSAS := scenarioHelper{}.getSecondaryRawContainerURLWithSAS(a, containerName)
raw := getDefaultListRawInput(rawContainerURLWithSAS.String())
raw.Properties = "VersionId"

runListAndVerify(a, raw, func(err error) {
a.Nil(err)

// validate that the no transfers were scheduled
a.Nil(mockedRPC.transfers)

// check if info logs contain the correct version id for each blob
msg := mockedLcm.GatherAllLogs(mockedLcm.infoLog)
for i, m := range msg {
a.True(strings.Contains(m, blobsToInclude[i]))
a.True(strings.Contains(m, "VersionId: "+versions[blobsToInclude[i]]))
}
})

}
33 changes: 33 additions & 0 deletions cmd/zt_scenario_helpers_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ func (scenarioHelper) getRawContainerURLWithSAS(a *assert.Assertions, containerN
return parsedURL
}

func (scenarioHelper) getSecondaryRawContainerURLWithSAS(a *assert.Assertions, containerName string) *url.URL {
accountName, accountKey := getSecondaryAccountAndKey()
credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
a.Nil(err)
cc := getContainerClientWithSAS(a, credential, containerName)

u := cc.URL()
parsedURL, err := url.Parse(u)
return parsedURL
}

func (scenarioHelper) getContainerClientWithSAS(a *assert.Assertions, containerName string) *container.Client {
accountName, accountKey := getAccountAndKey()
credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
Expand Down Expand Up @@ -858,6 +869,17 @@ func runCopyAndVerify(a *assert.Assertions, raw rawCopyCmdArgs, verifier func(er
verifier(err)
}

func runListAndVerify(a *assert.Assertions, raw rawListCmdArgs, verifier func(err error)) {
// the simulated user input should parse properly
cooked, err := raw.cook()
a.NoError(err)

err = cooked.HandleListContainerCommand()

// the err is passed to verified, which knows whether it is expected or not
verifier(err)
}

func validateUploadTransfersAreScheduled(a *assert.Assertions, sourcePrefix string, destinationPrefix string, expectedTransfers []string, mockedRPC interceptor) {
validateCopyTransfersAreScheduled(a, false, true, sourcePrefix, destinationPrefix, expectedTransfers, mockedRPC)
}
Expand Down Expand Up @@ -989,6 +1011,17 @@ func getDefaultRemoveRawInput(src string) rawCopyCmdArgs {
}
}

func getDefaultListRawInput(src string) rawListCmdArgs {
return rawListCmdArgs{
sourcePath: src,
Properties: "",
MachineReadable: false,
RunningTally: false,
MegaUnits: false,
trailingDot: "",
}
}

func getDefaultSetPropertiesRawInput(src string, params transferParams) rawCopyCmdArgs {
fromTo := common.EFromTo.BlobNone()
srcURL, _ := url.Parse(src)
Expand Down
Loading