mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-05 12:27:41 +00:00
garage(tests): Add random suffix to created buckets.
This commit is contained in:
@@ -56,4 +56,5 @@ netapp = "0.3.0"
|
||||
aws-sdk-s3 = "0.6"
|
||||
http = "0.2"
|
||||
|
||||
rand = "0.8"
|
||||
static_init = "1.0"
|
||||
|
||||
@@ -7,6 +7,7 @@ pub mod macros;
|
||||
pub mod client;
|
||||
pub mod ext;
|
||||
pub mod garage;
|
||||
pub mod util;
|
||||
|
||||
const REGION: Region = Region::from_static("garage-integ-test");
|
||||
|
||||
@@ -23,20 +24,27 @@ impl Context {
|
||||
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
|
||||
.command()
|
||||
.args(["bucket", "create", name])
|
||||
.args(["bucket", "create", &bucket_name])
|
||||
.quiet()
|
||||
.expect_success_status("Could not create bucket");
|
||||
self.garage
|
||||
.command()
|
||||
.args(["bucket", "allow"])
|
||||
.args(["--owner", "--read", "--write"])
|
||||
.arg(name)
|
||||
.arg(&bucket_name)
|
||||
.args(["--key", &self.garage.key.name])
|
||||
.quiet()
|
||||
.expect_success_status("Could not allow key for bucket");
|
||||
|
||||
bucket_name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -5,13 +5,13 @@ async fn test_simple() {
|
||||
use aws_sdk_s3::ByteStream;
|
||||
|
||||
let ctx = common::context();
|
||||
ctx.create_bucket("test-simple");
|
||||
let bucket = ctx.create_bucket("test-simple");
|
||||
|
||||
let data = ByteStream::from_static(b"Hello world!");
|
||||
|
||||
ctx.client
|
||||
.put_object()
|
||||
.bucket("test-simple")
|
||||
.bucket(&bucket)
|
||||
.key("test")
|
||||
.body(data)
|
||||
.send()
|
||||
@@ -21,7 +21,7 @@ async fn test_simple() {
|
||||
let res = ctx
|
||||
.client
|
||||
.get_object()
|
||||
.bucket("test-simple")
|
||||
.bucket(&bucket)
|
||||
.key("test")
|
||||
.send()
|
||||
.await
|
||||
@@ -35,13 +35,13 @@ async fn test_simple_2() {
|
||||
use aws_sdk_s3::ByteStream;
|
||||
|
||||
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!");
|
||||
|
||||
ctx.client
|
||||
.put_object()
|
||||
.bucket("test-simple-2")
|
||||
.bucket(&bucket)
|
||||
.key("test")
|
||||
.body(data)
|
||||
.send()
|
||||
@@ -51,7 +51,7 @@ async fn test_simple_2() {
|
||||
let res = ctx
|
||||
.client
|
||||
.get_object()
|
||||
.bucket("test-simple-2")
|
||||
.bucket(&bucket)
|
||||
.key("test")
|
||||
.send()
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user