garage(tests): Add random suffix to created buckets.

This commit is contained in:
Jill 2022-02-04 17:55:54 +01:00
parent cd13ea461b
commit d7decda3f4
No known key found for this signature in database
GPG key ID: 09A5A2688F13FAC1
5 changed files with 35 additions and 12 deletions

View file

@ -560,7 +560,7 @@ in
registry = "registry+https://github.com/rust-lang/crates.io-index"; registry = "registry+https://github.com/rust-lang/crates.io-index";
src = fetchCratesIo { inherit name version; sha256 = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469"; }; src = fetchCratesIo { inherit name version; sha256 = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469"; };
dependencies = { dependencies = {
${ if hostPlatform.config == "aarch64-apple-darwin" || hostPlatform.parsed.cpu.name == "aarch64" && hostPlatform.parsed.kernel.name == "linux" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; }; ${ if hostPlatform.parsed.cpu.name == "aarch64" && hostPlatform.parsed.kernel.name == "linux" || hostPlatform.config == "aarch64-apple-darwin" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; };
}; };
}); });
@ -985,6 +985,7 @@ in
devDependencies = { devDependencies = {
aws_sdk_s3 = rustPackages."registry+https://github.com/rust-lang/crates.io-index".aws-sdk-s3."0.6.0" { inherit profileName; }; aws_sdk_s3 = rustPackages."registry+https://github.com/rust-lang/crates.io-index".aws-sdk-s3."0.6.0" { inherit profileName; };
http = rustPackages."registry+https://github.com/rust-lang/crates.io-index".http."0.2.5" { inherit profileName; }; http = rustPackages."registry+https://github.com/rust-lang/crates.io-index".http."0.2.5" { inherit profileName; };
rand = rustPackages."registry+https://github.com/rust-lang/crates.io-index".rand."0.8.4" { inherit profileName; };
static_init = rustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init."1.0.2" { inherit profileName; }; static_init = rustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init."1.0.2" { inherit profileName; };
}; };
}); });
@ -2286,7 +2287,7 @@ in
]; ];
dependencies = { dependencies = {
${ if hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "linux" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; }; ${ if hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "linux" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; };
${ if hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "dragonfly" || hostPlatform.parsed.kernel.name == "freebsd" || hostPlatform.parsed.kernel.name == "illumos" || hostPlatform.parsed.kernel.name == "netbsd" || hostPlatform.parsed.kernel.name == "openbsd" || hostPlatform.parsed.kernel.name == "solaris" then "once_cell" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".once_cell."1.8.0" { inherit profileName; }; ${ if hostPlatform.parsed.kernel.name == "dragonfly" || hostPlatform.parsed.kernel.name == "freebsd" || hostPlatform.parsed.kernel.name == "illumos" || hostPlatform.parsed.kernel.name == "netbsd" || hostPlatform.parsed.kernel.name == "openbsd" || hostPlatform.parsed.kernel.name == "solaris" || hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "linux" then "once_cell" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".once_cell."1.8.0" { inherit profileName; };
${ if hostPlatform.parsed.cpu.name == "i686" || hostPlatform.parsed.cpu.name == "x86_64" || (hostPlatform.parsed.cpu.name == "aarch64" || hostPlatform.parsed.cpu.name == "armv6l" || hostPlatform.parsed.cpu.name == "armv7l") && (hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "fuchsia" || hostPlatform.parsed.kernel.name == "linux") then "spin" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".spin."0.5.2" { inherit profileName; }; ${ if hostPlatform.parsed.cpu.name == "i686" || hostPlatform.parsed.cpu.name == "x86_64" || (hostPlatform.parsed.cpu.name == "aarch64" || hostPlatform.parsed.cpu.name == "armv6l" || hostPlatform.parsed.cpu.name == "armv7l") && (hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "fuchsia" || hostPlatform.parsed.kernel.name == "linux") then "spin" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".spin."0.5.2" { inherit profileName; };
untrusted = rustPackages."registry+https://github.com/rust-lang/crates.io-index".untrusted."0.7.1" { inherit profileName; }; untrusted = rustPackages."registry+https://github.com/rust-lang/crates.io-index".untrusted."0.7.1" { inherit profileName; };
${ if hostPlatform.parsed.cpu.name == "wasm32" && hostPlatform.parsed.vendor.name == "unknown" && hostPlatform.parsed.kernel.name == "unknown" && hostPlatform.parsed.abi.name == "" then "web_sys" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".web-sys."0.3.56" { inherit profileName; }; ${ if hostPlatform.parsed.cpu.name == "wasm32" && hostPlatform.parsed.vendor.name == "unknown" && hostPlatform.parsed.kernel.name == "unknown" && hostPlatform.parsed.abi.name == "" then "web_sys" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".web-sys."0.3.56" { inherit profileName; };
@ -2645,7 +2646,7 @@ in
]; ];
dependencies = { dependencies = {
bitflags = rustPackages."registry+https://github.com/rust-lang/crates.io-index".bitflags."1.3.2" { inherit profileName; }; bitflags = rustPackages."registry+https://github.com/rust-lang/crates.io-index".bitflags."1.3.2" { inherit profileName; };
${ if hostPlatform.parsed.kernel.name == "android" || hostPlatform.parsed.kernel.name == "linux" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; }; ${ if hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "android" then "libc" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.115" { inherit profileName; };
${ if !(hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "android") then "parking_lot" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".parking_lot."0.11.2" { inherit profileName; }; ${ if !(hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "android") then "parking_lot" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".parking_lot."0.11.2" { inherit profileName; };
${ if !(hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "android") then "parking_lot_core" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".parking_lot_core."0.8.5" { inherit profileName; }; ${ if !(hostPlatform.parsed.kernel.name == "linux" || hostPlatform.parsed.kernel.name == "android") then "parking_lot_core" else null } = rustPackages."registry+https://github.com/rust-lang/crates.io-index".parking_lot_core."0.8.5" { inherit profileName; };
static_init_macro = buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init_macro."1.0.2" { profileName = "__noProfile"; }; static_init_macro = buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".static_init_macro."1.0.2" { profileName = "__noProfile"; };

View file

@ -56,4 +56,5 @@ netapp = "0.3.0"
aws-sdk-s3 = "0.6" aws-sdk-s3 = "0.6"
http = "0.2" http = "0.2"
rand = "0.8"
static_init = "1.0" static_init = "1.0"

View file

@ -7,6 +7,7 @@ pub mod macros;
pub mod client; pub mod client;
pub mod ext; pub mod ext;
pub mod garage; pub mod garage;
pub mod util;
const REGION: Region = Region::from_static("garage-integ-test"); const REGION: Region = Region::from_static("garage-integ-test");
@ -23,20 +24,27 @@ impl Context {
Context { garage, client } Context { garage, client }
} }
pub fn create_bucket(&self, name: &str) { /// Create an unique bucket with a random suffix.
///
/// Return the created bucket full name.
pub fn create_bucket(&self, name: &str) -> String {
let bucket_name = format!("{}-{}", name, util::random_id(6));
self.garage self.garage
.command() .command()
.args(["bucket", "create", name]) .args(["bucket", "create", &bucket_name])
.quiet() .quiet()
.expect_success_status("Could not create bucket"); .expect_success_status("Could not create bucket");
self.garage self.garage
.command() .command()
.args(["bucket", "allow"]) .args(["bucket", "allow"])
.args(["--owner", "--read", "--write"]) .args(["--owner", "--read", "--write"])
.arg(name) .arg(&bucket_name)
.args(["--key", &self.garage.key.name]) .args(["--key", &self.garage.key.name])
.quiet() .quiet()
.expect_success_status("Could not allow key for bucket"); .expect_success_status("Could not allow key for bucket");
bucket_name
} }
} }

View file

@ -0,0 +1,13 @@
pub fn random_id(len: usize) -> String {
use rand::distributions::Slice;
use rand::Rng;
static ALPHABET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789.";
let rng = rand::thread_rng();
rng.sample_iter(Slice::new(ALPHABET).unwrap())
.map(|b| char::from(*b))
.filter(|c| c.is_ascii_lowercase() || c.is_ascii_digit())
.take(len)
.collect()
}

View file

@ -5,13 +5,13 @@ async fn test_simple() {
use aws_sdk_s3::ByteStream; use aws_sdk_s3::ByteStream;
let ctx = common::context(); let ctx = common::context();
ctx.create_bucket("test-simple"); let bucket = ctx.create_bucket("test-simple");
let data = ByteStream::from_static(b"Hello world!"); let data = ByteStream::from_static(b"Hello world!");
ctx.client ctx.client
.put_object() .put_object()
.bucket("test-simple") .bucket(&bucket)
.key("test") .key("test")
.body(data) .body(data)
.send() .send()
@ -21,7 +21,7 @@ async fn test_simple() {
let res = ctx let res = ctx
.client .client
.get_object() .get_object()
.bucket("test-simple") .bucket(&bucket)
.key("test") .key("test")
.send() .send()
.await .await
@ -35,13 +35,13 @@ async fn test_simple_2() {
use aws_sdk_s3::ByteStream; use aws_sdk_s3::ByteStream;
let ctx = common::context(); let ctx = common::context();
ctx.create_bucket("test-simple-2"); let bucket = ctx.create_bucket("test-simple-2");
let data = ByteStream::from_static(b"Hello world!"); let data = ByteStream::from_static(b"Hello world!");
ctx.client ctx.client
.put_object() .put_object()
.bucket("test-simple-2") .bucket(&bucket)
.key("test") .key("test")
.body(data) .body(data)
.send() .send()
@ -51,7 +51,7 @@ async fn test_simple_2() {
let res = ctx let res = ctx
.client .client
.get_object() .get_object()
.bucket("test-simple-2") .bucket(&bucket)
.key("test") .key("test")
.send() .send()
.await .await