-
Notifications
You must be signed in to change notification settings - Fork 250
Fixed panic for s3 and gcp transfers #3276
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
Open
gapra-msft
wants to merge
7
commits into
main
Choose a base branch
from
gapra/s3gcpsegfault
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−55
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f736f65
Fixed seg fault for s3 and gcp transfers
gapra-msft 65f7c08
remove condition to call method
gapra-msft 772d3b9
Apply suggestion from @Copilot
gapra-msft 3dfe423
Apply suggestion from @Copilot
gapra-msft 6257bd1
Merge branch 'main' into gapra/s3gcpsegfault
gapra-msft aef1fc9
addressed comments
gapra-msft e2c769d
refactor code to allow testability
gapra-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-storage-azcopy/v10/common" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestValidateProtocolCompatibility(t *testing.T) { | ||
| a := assert.New(t) | ||
| ctx := context.Background() | ||
|
|
||
| // Test cases where validation should NOT be called (no File locations involved) | ||
| testCases := []struct { | ||
| name string | ||
| fromTo common.FromTo | ||
| shouldValidate bool | ||
| description string | ||
| }{ | ||
| { | ||
| name: "S3ToBlob", | ||
| fromTo: common.EFromTo.S3Blob(), | ||
| shouldValidate: false, | ||
| description: "S3 to Blob should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "GCPToBlob", | ||
| fromTo: common.EFromTo.GCPBlob(), | ||
| shouldValidate: false, | ||
| description: "GCP to Blob should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "LocalToBlob", | ||
| fromTo: common.EFromTo.LocalBlob(), | ||
| shouldValidate: false, | ||
| description: "Local to Blob should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "BlobToLocal", | ||
| fromTo: common.EFromTo.BlobLocal(), | ||
| shouldValidate: false, | ||
| description: "Blob to Local should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "BlobToBlob", | ||
| fromTo: common.EFromTo.BlobBlob(), | ||
| shouldValidate: false, | ||
| description: "Blob to Blob should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "LocalToBlobFS", | ||
| fromTo: common.EFromTo.LocalBlobFS(), | ||
| shouldValidate: false, | ||
| description: "Local to BlobFS should not validate (neither side is File)", | ||
| }, | ||
| { | ||
| name: "LocalToFile", | ||
| fromTo: common.EFromTo.LocalFile(), | ||
| shouldValidate: true, | ||
| description: "Local to File should validate (destination is File)", | ||
| }, | ||
| { | ||
| name: "FileToLocal", | ||
| fromTo: common.EFromTo.FileLocal(), | ||
| shouldValidate: true, | ||
| description: "File to Local should validate (source is File)", | ||
| }, | ||
| { | ||
| name: "LocalToFileNFS", | ||
| fromTo: common.EFromTo.LocalFileNFS(), | ||
| shouldValidate: true, | ||
| description: "Local to FileNFS should validate (destination is FileNFS)", | ||
| }, | ||
| { | ||
| name: "FileNFSToLocal", | ||
| fromTo: common.EFromTo.FileNFSLocal(), | ||
| shouldValidate: true, | ||
| description: "FileNFS to Local should validate (source is FileNFS)", | ||
| }, | ||
| { | ||
| name: "FileToFile", | ||
| fromTo: common.EFromTo.FileFile(), | ||
| shouldValidate: true, | ||
| description: "File to File should validate (both sides are File)", | ||
| }, | ||
| { | ||
| name: "FileNFSToFileNFS", | ||
| fromTo: common.EFromTo.FileNFSFileNFS(), | ||
| shouldValidate: true, | ||
| description: "FileNFS to FileNFS should validate (both sides are FileNFS)", | ||
| }, | ||
| { | ||
| name: "FileToBlob", | ||
| fromTo: common.EFromTo.FileBlob(), | ||
| shouldValidate: true, | ||
| description: "File to Blob should validate (source is File)", | ||
| }, | ||
| { | ||
| name: "BlobToFile", | ||
| fromTo: common.EFromTo.BlobFile(), | ||
| shouldValidate: true, | ||
| description: "Blob to File should validate (destination is File)", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| // Create dummy resource strings | ||
| src := common.ResourceString{Value: "https://source.example.com/path"} | ||
| dst := common.ResourceString{Value: "https://dest.example.com/path"} | ||
|
|
||
| // For non-File transfers, we can pass nil service clients since validation should be skipped | ||
| // For File transfers, we would need proper service clients, but we're testing the conditional logic | ||
| var srcClient, dstClient *common.ServiceClient | ||
|
|
||
| if !tc.shouldValidate { | ||
| // Test that validation is skipped when no File locations are involved | ||
| // This should not panic even with nil service clients | ||
| err := validateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient) | ||
| a.NoError(err, "validateProtocolCompatibility should not fail for %s: %s", tc.name, tc.description) | ||
| } else { | ||
| // For File transfers, we expect the function to attempt validation | ||
| // Since we're passing nil service clients, we expect it to fail gracefully | ||
| // This tests that the conditional logic correctly identifies File transfers | ||
| err := validateProtocolCompatibility(ctx, tc.fromTo, src, dst, srcClient, dstClient) | ||
| // We expect an error here because we're passing nil service clients for File transfers | ||
| // The important thing is that it doesn't panic and attempts validation | ||
| if tc.fromTo.From().IsFile() || tc.fromTo.To().IsFile() { | ||
| a.Error(err, "validateProtocolCompatibility should attempt validation for %s and fail with nil clients: %s", tc.name, tc.description) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateProtocolCompatibility_ConditionalLogic(t *testing.T) { | ||
| a := assert.New(t) | ||
| ctx := context.Background() | ||
|
|
||
| // Test the specific conditional logic | ||
| src := common.ResourceString{Value: "https://source.example.com/path"} | ||
| dst := common.ResourceString{Value: "https://dest.example.com/path"} | ||
|
|
||
| // Test that S3->Blob doesn't call validation (should not panic with nil clients) | ||
| err := validateProtocolCompatibility(ctx, common.EFromTo.S3Blob(), src, dst, nil, nil) | ||
| a.NoError(err, "S3->Blob should skip validation and not panic with nil service clients") | ||
|
|
||
| // Test that GCP->Blob doesn't call validation (should not panic with nil clients) | ||
| err = validateProtocolCompatibility(ctx, common.EFromTo.GCPBlob(), src, dst, nil, nil) | ||
| a.NoError(err, "GCP->Blob should skip validation and not panic with nil service clients") | ||
|
|
||
| // Test that Local->Blob doesn't call validation (should not panic with nil clients) | ||
| err = validateProtocolCompatibility(ctx, common.EFromTo.LocalBlob(), src, dst, nil, nil) | ||
| a.NoError(err, "Local->Blob should skip validation and not panic with nil service clients") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.