feat: add tests
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
44fbf1f362
commit
e994df19cf
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1178,6 +1178,7 @@ dependencies = [
|
|||||||
"axum 0.7.4",
|
"axum 0.7.4",
|
||||||
"clap",
|
"clap",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"lazy_static",
|
||||||
"mockall",
|
"mockall",
|
||||||
"mockall_double",
|
"mockall_double",
|
||||||
"nats",
|
"nats",
|
||||||
|
@ -28,4 +28,5 @@ tar = "0.4.40"
|
|||||||
tonic-build = "0.11.0"
|
tonic-build = "0.11.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
lazy_static = "1.4.0"
|
||||||
mockall = "0.12.1"
|
mockall = "0.12.1"
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
api::axum_serve,
|
|
||||||
app::{App, SharedApp},
|
|
||||||
grpc::tonic_serve,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||||
pub struct Command {
|
pub struct Command {
|
||||||
@ -29,22 +23,41 @@ impl Command {
|
|||||||
let cli = Command::parse();
|
let cli = Command::parse();
|
||||||
|
|
||||||
if let Some(Commands::Serve { host, grpc_host }) = cli.command {
|
if let Some(Commands::Serve { host, grpc_host }) = cli.command {
|
||||||
tracing_subscriber::fmt::init();
|
server::run_server(host, grpc_host).await?;
|
||||||
|
|
||||||
tracing::info!("Starting service");
|
|
||||||
|
|
||||||
let app = SharedApp::new(App::new().await?);
|
|
||||||
|
|
||||||
tokio::select! {
|
|
||||||
res = axum_serve(host, app.clone()) => {
|
|
||||||
res?;
|
|
||||||
},
|
|
||||||
res = tonic_serve(grpc_host, app.clone()) => {
|
|
||||||
res?;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod server {
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
api::axum_serve,
|
||||||
|
app::{App, SharedApp},
|
||||||
|
grpc::tonic_serve,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn run_server(
|
||||||
|
host: impl Into<SocketAddr>,
|
||||||
|
grpc_host: impl Into<SocketAddr>,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
tracing::info!("Starting service");
|
||||||
|
|
||||||
|
let app = SharedApp::new(App::new().await?);
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
res = axum_serve(host.into(), app.clone()) => {
|
||||||
|
res?;
|
||||||
|
},
|
||||||
|
res = tonic_serve(grpc_host.into(), app.clone()) => {
|
||||||
|
res?;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
48
crates/flux-releaser/tests/publish_artifacts.rs
Normal file
48
crates/flux-releaser/tests/publish_artifacts.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
struct Server {}
|
||||||
|
|
||||||
|
impl Server {
|
||||||
|
pub async fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start(&self) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static INIT: std::sync::Once = std::sync::Once::new();
|
||||||
|
|
||||||
|
// Makes sure the setup is ready for execution
|
||||||
|
async fn is_ready() -> anyhow::Result<()> {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn setup() -> anyhow::Result<()> {
|
||||||
|
INIT.call_once(|| {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
println!("once was created once");
|
||||||
|
Server::new().await.start().await.unwrap();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
is_ready().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn can_create_artifact() -> anyhow::Result<()> {
|
||||||
|
setup().await?;
|
||||||
|
anyhow::bail!("failed one");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn can_more_create_artifact() -> anyhow::Result<()> {
|
||||||
|
setup().await?;
|
||||||
|
|
||||||
|
anyhow::bail!("failed two");
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user