feat: with comparing contents
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-02-18 22:37:54 +01:00
parent 02e70fe268
commit a17dd2bd10
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
5 changed files with 52 additions and 2 deletions

1
Cargo.lock generated
View File

@ -1184,6 +1184,7 @@ dependencies = [
"lazy_static",
"nats",
"prost",
"rand",
"reqwest",
"serde",
"serde_json",

View File

@ -23,6 +23,7 @@ nats = "0.24.1"
walkdir = "2.4.0"
tar = "0.4.40"
tokio-stream = { version = "0.1.14", features = ["full"] }
rand = "0.8.5"
[build-dependencies]
tonic-build = "0.11.0"

View File

@ -72,4 +72,32 @@ impl FileStore {
Ok(archive_path)
}
pub async fn get_temp(&self, artifact_id: UploadArtifactID) -> anyhow::Result<PathBuf> {
tracing::trace!("getting archive: {}", artifact_id.to_string());
let archive_name = format!("temp/{}.tar", &artifact_id.to_string());
let obj = self
.client
.get_object()
.bucket("mybucket")
.key(&archive_name)
.send()
.await?;
let archive_path = temp_dir()
.join("flux_releaser")
.join("downloads/cache")
.join(&archive_name);
tokio::fs::create_dir_all(archive_path.parent().unwrap()).await?;
let mut archive_file = tokio::fs::File::create(&archive_path).await?;
let mut buf_reader = BufReader::new(obj.body.into_async_read());
tokio::io::copy(&mut buf_reader, &mut archive_file).await?;
tracing::debug!("created archive: {}", archive_path.display());
Ok(archive_path)
}
}

View File

@ -51,6 +51,16 @@ impl From<uuid::Uuid> for UploadArtifactID {
}
}
impl TryFrom<String> for UploadArtifactID {
type Error = anyhow::Error;
fn try_from(value: String) -> Result<Self, Self::Error> {
let uuid = uuid::Uuid::parse_str(&value)?;
Ok(Self(uuid))
}
}
impl Deref for UploadArtifactID {
type Target = uuid::Uuid;

View File

@ -12,6 +12,7 @@ use flux_releaser::{
},
services::file_store::extensions::FileStoreExt,
};
use rand::{thread_rng, Rng};
use tokio::{net::TcpListener, runtime::Runtime, time::sleep};
use uuid::Uuid;
@ -144,7 +145,9 @@ async fn can_upload_artifact() -> anyhow::Result<()> {
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
let bytes: [u8; 10000] = [0; 10000];
let mut bytes: [u8; 10000] = [0; 10000];
thread_rng().fill(&mut bytes[..]);
let chunks = bytes
.chunks(bytes.len() / 100)
@ -157,7 +160,14 @@ async fn can_upload_artifact() -> anyhow::Result<()> {
let resp = client.upload_artifact(req).await?;
assert!(!resp.into_inner().upload_id.is_empty());
let upload_id = resp.into_inner().upload_id;
assert!(!upload_id.is_empty());
let actual_path = app.file_store().get_temp(upload_id.try_into()?).await?;
let actual_content = tokio::fs::read(actual_path).await?;
assert_eq!(&bytes[..], actual_content.as_slice());
Ok(())
}