Skip to content

test(storage): add CRD tests #1952

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

Merged
merged 2 commits into from
Apr 29, 2025
Merged

Conversation

dbolduc
Copy link
Member

@dbolduc dbolduc commented Apr 28, 2025

Part of the work for #1813, will be useful for testing #1951

Add bucket CRUD tests minus the U.

@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Apr 28, 2025
@dbolduc dbolduc marked this pull request as ready for review April 28, 2025 23:09
@dbolduc dbolduc requested a review from a team as a code owner April 28, 2025 23:09
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.67%. Comparing base (9761ec9) to head (a90f3c2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1952   +/-   ##
=======================================
  Coverage   95.67%   95.67%           
=======================================
  Files          57       57           
  Lines        2056     2056           
=======================================
  Hits         1967     1967           
  Misses         89       89           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@coryan coryan left a comment

Choose a reason for hiding this comment

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

Lots of nits, nothing blocking I think.


println!("\nTesting create_bucket()");
let create = client
.create_bucket("projects/_", bucket_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

optional: As you may recall, the rate limit for this call is 0.5Hz. We should to adjust the backoff to start a 2s, at least for this call.

Copy link
Member Author

Choose a reason for hiding this comment

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

the rate limit for this call is 0.5Hz.

I did read that. I saw we ran CRUD tests for buckets in Cloud C++ so figured it couldn't be that bad to run them here.

adjust the backoff to start a 2s

Good idea. Done.

assert_eq!(get.name, bucket_name);

println!("\nTesting list_buckets()");
let mut paginator = client
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I have taken to calling these "items"... they certainly are not a paginator after the items() call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack, I am going to call them bucket(s). Seems more specific.

Comment on lines 77 to 78
"missing bucket name {} in {bucket_names:?}",
&bucket_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
"missing bucket name {} in {bucket_names:?}",
&bucket_name
"missing bucket name {bucket_name} in {bucket_names:?}"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.


pub(crate) fn random_bucket_id() -> String {
const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
const PREFIX: &str = "rust-sdk-testing-";
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we use the integration-tests label we do not need a long prefix like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the prefix though. It makes it more obvious what these things are if they leak (especially in a testing project). I don't mind sacrificing some bits of randomness.

Comment on lines 153 to 157
let mut bucket_id = String::new();
for _ in 0..(BUCKET_ID_LENGTH - PREFIX.len()) {
let idx = rand::rng().random_range(0..CHARSET.len());
bucket_id.push(CHARSET[idx] as char);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider:

Suggested change
let mut bucket_id = String::new();
for _ in 0..(BUCKET_ID_LENGTH - PREFIX.len()) {
let idx = rand::rng().random_range(0..CHARSET.len());
bucket_id.push(CHARSET[idx] as char);
}
let id = std::iter::from_fn(|| move { rand::rng().random_range(0..CHARSET.len()) })
.take(BUCKET_ID_LENGTH - PREFIX.len())
.map(|idx| char::from(CHARSET[idx])
.collect();

Or if you want to be nice, add an analog to Alphanumeric for lowercase characters to lib.rs.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are now the proud owner of RandomChars which impls rand::distr::Distribution<u8> for any set of characters we may care about.

@dbolduc dbolduc merged commit 70fe915 into googleapis:main Apr 29, 2025
21 checks passed
@dbolduc dbolduc deleted the test-storage-bucket-crd branch April 29, 2025 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants