-
Notifications
You must be signed in to change notification settings - Fork 86
oadp-1.5: Fix S3 bucket region unit tests by adding mocking support (#2052) #2071
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
base: oadp-1.5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,16 +13,25 @@ import ( | |
| "github.com/aws/aws-sdk-go/aws/request" | ||
| ) | ||
|
|
||
| // GetBucketRegionFunc is the function used to get bucket region. | ||
| // It can be replaced in tests for mocking. | ||
| var GetBucketRegionFunc = getBucketRegionImpl | ||
|
|
||
| func BucketRegionIsDiscoverable(bucket string) bool { | ||
| _, err := GetBucketRegion(bucket) | ||
| _, err := GetBucketRegionFunc(bucket) | ||
| return err == nil | ||
| } | ||
|
|
||
| // GetBucketRegion returns the AWS region that a bucket is in, or an error | ||
| // if the region cannot be determined. | ||
| // if the region cannot be determined. This is a wrapper that calls GetBucketRegionFunc. | ||
| func GetBucketRegion(bucket string) (string, error) { | ||
| return GetBucketRegionFunc(bucket) | ||
| } | ||
|
Comment on lines
25
to
+29
|
||
|
|
||
| // getBucketRegionImpl is the actual implementation that calls AWS. | ||
| // copied from https://github.com/openshift/openshift-velero-plugin/pull/223/files#diff-da482ef606b3938b09ae46990a60eb0ad49ebfb4885eb1af327d90f215bf58b1 | ||
| // modified to aws-sdk-go-v2 | ||
| func GetBucketRegion(bucket string) (string, error) { | ||
| func getBucketRegionImpl(bucket string) (string, error) { | ||
| var region string | ||
| // GetBucketRegion will attempt to get the region for a bucket using the client's configured region to determine | ||
| // which AWS partition to perform the query on. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock setup for GetBucketRegionFunc appears unnecessary in this test. The UpdateBackupStorageLocation function being tested only calls aws.StripDefaultPorts() and does not invoke any bucket region discovery functionality. The mock checks for a bucket name "openshift-velero-plugin-s3-auto-region-test-1" that doesn't appear in any of the test cases in this test function. This mock should be removed as it adds confusion without providing value.