Skip to content

Conversation

@kaovilai
Copy link
Member

@kaovilai kaovilai commented Jan 19, 2026

cp: #2052
The unit tests for S3 bucket region auto-discovery were making real
network calls to AWS, causing failures in CI environments without
network access to the test buckets.

Changes:

  • Add GetBucketRegionFunc variable in pkg/storage/aws/s3.go to enable
    mocking in tests
  • Refactor s3_test.go to use mocks instead of real AWS calls
  • Add mock setup in bsl_test.go for tests using DiscoverableBucket
  • Add mock setup in common_test.go for TestUpdateBackupStorageLocation

🤖 Generated with Claude Code

Co-authored-by: Claude Opus 4.5 noreply@anthropic.com

Why the changes were made

How to test the changes made

…2052)

The unit tests for S3 bucket region auto-discovery were making real
network calls to AWS, causing failures in CI environments without
network access to the test buckets.

Changes:
- Add GetBucketRegionFunc variable in pkg/storage/aws/s3.go to enable
  mocking in tests
- Refactor s3_test.go to use mocks instead of real AWS calls
- Add mock setup in bsl_test.go for tests using DiscoverableBucket
- Add mock setup in common_test.go for TestUpdateBackupStorageLocation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 19, 2026 14:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • do-not-merge/work-in-progress

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes unit tests for S3 bucket region auto-discovery that were making real network calls to AWS, causing failures in CI environments without network access. The solution introduces a mockable function variable to enable testing without actual AWS API calls.

Changes:

  • Add mocking infrastructure to pkg/storage/aws/s3.go with GetBucketRegionFunc variable
  • Refactor s3_test.go to use mocks instead of real AWS API calls
  • Add mock setup in test files where bucket region discovery is used

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/storage/aws/s3.go Introduces GetBucketRegionFunc variable for mocking and refactors GetBucketRegion to delegate to it
pkg/storage/aws/s3_test.go Updates tests to use mocks instead of real AWS buckets, improving test reliability and removing network dependencies
pkg/common/common_test.go Adds mock setup for GetBucketRegionFunc (though this appears unnecessary for the function being tested)
internal/controller/bsl_test.go Adds mock setup to return region for DiscoverableBucket constant used in test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +468 to +476
// Mock GetBucketRegionFunc to return a region for the test bucket
originalGetBucketRegionFunc := aws.GetBucketRegionFunc
aws.GetBucketRegionFunc = func(bucket string) (string, error) {
if bucket == "openshift-velero-plugin-s3-auto-region-test-1" {
return "us-east-1", nil
}
return "", errors.New("bucket region not discoverable")
}
defer func() { aws.GetBucketRegionFunc = originalGetBucketRegionFunc }()
Copy link

Copilot AI Jan 19, 2026

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.

Suggested change
// Mock GetBucketRegionFunc to return a region for the test bucket
originalGetBucketRegionFunc := aws.GetBucketRegionFunc
aws.GetBucketRegionFunc = func(bucket string) (string, error) {
if bucket == "openshift-velero-plugin-s3-auto-region-test-1" {
return "us-east-1", nil
}
return "", errors.New("bucket region not discoverable")
}
defer func() { aws.GetBucketRegionFunc = originalGetBucketRegionFunc }()

Copilot uses AI. Check for mistakes.
Comment on lines 25 to +29
// 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)
}
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment describes GetBucketRegion as "a wrapper that calls GetBucketRegionFunc", which is accurate but could be clearer. Since GetBucketRegion is the public API function that was refactored to enable mocking, consider updating the comment to clarify its purpose, such as: "GetBucketRegion returns the AWS region that a bucket is in, or an error if the region cannot be determined. It delegates to GetBucketRegionFunc which can be mocked in tests."

Copilot uses AI. Check for mistakes.
@kaovilai
Copy link
Member Author

/retest

@openshift-ci
Copy link

openshift-ci bot commented Jan 23, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kaovilai, shubham-pampattiwar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [kaovilai,shubham-pampattiwar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link

openshift-ci bot commented Jan 23, 2026

@kaovilai: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants