Skip to content

Commit

Permalink
Apply clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Apr 3, 2023
1 parent 8bc0f6d commit f0392e3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/abq_cli/Cargo.toml
Expand Up @@ -64,3 +64,4 @@ regex.workspace = true

[features]
test-abq-jest = []
s3 = [ "abq_queue/s3" ]
57 changes: 55 additions & 2 deletions crates/abq_queue/src/persistence/remote/s3.rs
Expand Up @@ -94,7 +94,7 @@ fn build_key(prefix: &str, kind: PersistenceKind, run_id: RunId) -> impl Into<St
PersistenceKind::Manifest => "manifest",
PersistenceKind::Results => "results",
};
[&prefix, run_id.0.as_str(), kind_str].join("/")
[prefix, run_id.0.as_str(), kind_str].join("/")
}

#[async_trait]
Expand Down Expand Up @@ -124,7 +124,7 @@ where
run_id: RunId,
into_local_path: &Path,
) -> OpaqueResult<()> {
let key = build_key(&self.key_prefix(), kind, run_id);
let key = build_key(self.key_prefix(), kind, run_id);
let get_object = self.get(key).await.located(here!())?;

let mut body = get_object.body.into_async_read();
Expand Down Expand Up @@ -199,6 +199,7 @@ mod test {
use super::{build_key, PersistenceKind};
use crate::persistence::remote::RemotePersistence;
use abq_utils::net_protocol::workers::RunId;
use aws_sdk_s3::error::SdkError;
use aws_sdk_s3::operation::get_object::GetObjectOutput;
use aws_sdk_s3::operation::put_object::PutObjectOutput;
use aws_sdk_s3::primitives::ByteStream;
Expand Down Expand Up @@ -276,4 +277,56 @@ mod test {

assert_eq!(buf, b"manifest-body");
}

#[tokio::test]
async fn store_error() {
let s3 = S3Fake::new(
"bucket-prefix",
|key, body| {
assert_eq!(key, "bucket-prefix/test-run-id/manifest");
assert_eq!(body, b"manifest-body");
Err(SdkError::timeout_error("timed out"))
},
|_| unreachable!(),
);

let mut manifest = NamedTempFile::new().unwrap();
io::Write::write_all(&mut manifest, b"manifest-body").unwrap();

let err = s3
.store(
PersistenceKind::Manifest,
RunId("test-run-id".to_owned()),
manifest.path(),
)
.await
.unwrap_err();

assert!(err.to_string().contains("timed out"));
}

#[tokio::test]
async fn load_error() {
let s3 = S3Fake::new(
"bucket-prefix",
|_key, _body| unreachable!(),
|key| {
assert_eq!(key, "bucket-prefix/test-run-id/manifest");
Err(SdkError::timeout_error("timed out"))
},
);

let manifest = NamedTempFile::new().unwrap();

let err = s3
.load(
PersistenceKind::Manifest,
RunId("test-run-id".to_owned()),
manifest.path(),
)
.await
.unwrap_err();

assert!(err.to_string().contains("timed out"));
}
}

0 comments on commit f0392e3

Please sign in to comment.