feat: add actual upload
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-02-19 22:50:49 +01:00
parent a17dd2bd10
commit d35f5c8f22
18 changed files with 400 additions and 149 deletions

View File

@@ -1,19 +1,20 @@
use std::{
env::temp_dir,
net::{Ipv4Addr, SocketAddr},
sync::Arc,
time::Duration,
};
use anyhow::Context;
use flux_releaser::{
app::SharedApp,
grpc::gen::{
flux_releaser_client::FluxReleaserClient, CommitArtifactRequest, UploadArtifactRequest,
app::{LocalApp, SharedApp, SharedLocalApp},
grpc::gen::flux_releaser_client::FluxReleaserClient,
services::{
archive::ArchiveFile, file_store::extensions::FileStoreExt,
flux_local_cluster::extensions::FluxLocalClusterManagerExt,
flux_releaser_uploader::FluxReleaserUploader,
},
services::file_store::extensions::FileStoreExt,
};
use rand::{thread_rng, Rng};
use tokio::{net::TcpListener, runtime::Runtime, time::sleep};
use tokio::{net::TcpListener, runtime::Runtime, sync::Mutex, time::sleep};
use uuid::Uuid;
struct Server {
@@ -139,35 +140,34 @@ async fn setup() -> anyhow::Result<(Endpoints, SharedApp)> {
Ok(unsafe { (ENDPOINTS.clone().unwrap(), APP.clone().unwrap()) })
}
async fn local_setup(endpoints: Endpoints) -> anyhow::Result<SharedLocalApp> {
Ok(SharedLocalApp::new(
LocalApp::new(format!("http://{}", endpoints.grpc)).await?,
))
}
#[tokio::test]
async fn can_upload_artifact() -> anyhow::Result<()> {
std::env::set_var("RUST_LOG", "flux_releaser=trace");
let (endpoints, app) = setup().await?;
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
let client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
let client = FluxReleaserUploader::new(Arc::new(Mutex::new(client)));
let mut bytes: [u8; 10000] = [0; 10000];
thread_rng().fill(&mut bytes[..]);
let chunks = bytes
.chunks(bytes.len() / 100)
.map(|ch| UploadArtifactRequest {
content: ch.to_vec(),
let bytes: Vec<u8> = vec![0; 10_000_000];
let upload_id = client
.upload_archive(ArchiveFile {
content: bytes.clone(),
})
.collect::<Vec<_>>();
.await?;
let req = tonic::Request::new(tokio_stream::iter(chunks));
assert!(!upload_id.to_string().is_empty());
let resp = client.upload_artifact(req).await?;
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_path = app.file_store().get_temp(upload_id).await?;
let actual_content = tokio::fs::read(actual_path).await?;
assert_eq!(&bytes[..], actual_content.as_slice());
assert_eq!(&bytes, &actual_content);
Ok(())
}
@@ -177,40 +177,26 @@ async fn can_publish_artifact() -> anyhow::Result<()> {
std::env::set_var("RUST_LOG", "flux_releaser=trace");
let (endpoints, app) = setup().await?;
let local_app = local_setup(endpoints.clone()).await?;
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
let test_id = Uuid::new_v4();
let temp = temp_dir()
.join("flux_releaser")
.join("tests")
.join(test_id.to_string());
let file_path = temp
.join("clusters")
.join(Uuid::new_v4().to_string())
.join("some-file.yaml");
tokio::fs::create_dir_all(file_path.parent().unwrap()).await?;
let _ = tokio::fs::File::create(file_path).await?;
let resp = client
.commit_artifact(CommitArtifactRequest {
app: "some-app".into(),
branch: "some-branch".into(),
folder: temp.to_string_lossy().to_string(),
})
let upload_id = local_app
.flux_local_cluster_manager()
.package_clusters("testdata/flux_local_cluster")
.await?;
let artifact = resp.into_inner();
let archive = app
.file_store()
.get_archive(artifact.artifact_id.try_into()?)
.await?;
let archive = app.file_store().get_temp(upload_id.clone()).await?;
assert!(archive.exists());
let artifact_id = local_app
.flux_local_cluster_manager()
.commit_artifact("some-app", "some-branch", upload_id)
.await?;
let artifact = app.file_store().get_archive(artifact_id).await?;
assert!(artifact.exists());
Ok(())
}