Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -6,10 +6,13 @@ use std::{
|
||||
|
||||
use anyhow::Context;
|
||||
use flux_releaser::{
|
||||
app::SharedApp, grpc::gen::HelloRequest, services::file_store::extensions::FileStoreExt,
|
||||
app::SharedApp,
|
||||
grpc::gen::{
|
||||
flux_releaser_client::FluxReleaserClient, CommitArtifactRequest, UploadArtifactRequest,
|
||||
},
|
||||
services::file_store::extensions::FileStoreExt,
|
||||
};
|
||||
use tokio::{net::TcpListener, runtime::Runtime, time::sleep};
|
||||
use tonic::transport::Channel;
|
||||
use uuid::Uuid;
|
||||
|
||||
struct Server {
|
||||
@@ -69,7 +72,7 @@ where
|
||||
loop {
|
||||
match task().await {
|
||||
Ok(result) => return Ok(result),
|
||||
Err(e) if retries < max_retries => {
|
||||
Err(_e) if retries < max_retries => {
|
||||
sleep(Duration::from_millis(delay)).await;
|
||||
delay *= 2; // Exponential backoff
|
||||
retries += 1;
|
||||
@@ -136,23 +139,36 @@ async fn setup() -> anyhow::Result<(Endpoints, SharedApp)> {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn can_create_artifact() -> anyhow::Result<()> {
|
||||
setup().await?;
|
||||
async fn can_upload_artifact() -> anyhow::Result<()> {
|
||||
let (endpoints, app) = setup().await?;
|
||||
|
||||
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
|
||||
|
||||
let bytes: [u8; 10000] = [0; 10000];
|
||||
|
||||
let chunks = bytes
|
||||
.chunks(bytes.len() / 100)
|
||||
.map(|ch| UploadArtifactRequest {
|
||||
content: ch.to_vec(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let req = tonic::Request::new(tokio_stream::iter(chunks));
|
||||
|
||||
let resp = client.upload_artifact(req).await?;
|
||||
|
||||
assert!(!resp.into_inner().upload_id.is_empty());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn can_more_create_artifact() -> anyhow::Result<()> {
|
||||
async fn can_publish_artifact() -> anyhow::Result<()> {
|
||||
std::env::set_var("RUST_LOG", "flux_releaser=trace");
|
||||
|
||||
let (endpoints, app) = setup().await?;
|
||||
|
||||
let mut client = flux_releaser::grpc::gen::greeter_client::GreeterClient::connect(format!(
|
||||
"http://{}",
|
||||
endpoints.grpc
|
||||
))
|
||||
.await?;
|
||||
let mut client = FluxReleaserClient::connect(format!("http://{}", endpoints.grpc)).await?;
|
||||
|
||||
let test_id = Uuid::new_v4();
|
||||
|
||||
@@ -169,7 +185,7 @@ async fn can_more_create_artifact() -> anyhow::Result<()> {
|
||||
let _ = tokio::fs::File::create(file_path).await?;
|
||||
|
||||
let resp = client
|
||||
.say_hello(HelloRequest {
|
||||
.commit_artifact(CommitArtifactRequest {
|
||||
app: "some-app".into(),
|
||||
branch: "some-branch".into(),
|
||||
folder: temp.to_string_lossy().to_string(),
|
||||
|
Reference in New Issue
Block a user