Skip to content

Commit

Permalink
feat: write "ok" endpoint
Browse files Browse the repository at this point in the history
The test passes while it's running in the background
  • Loading branch information
jasonribble committed Oct 17, 2024
1 parent 7bc463b commit b77bfd9
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 1 deletion.
115 changes: 114 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors = ["Jason Ribble <[email protected]>"]
[dependencies]
anyhow = "1.0.86"
async-trait = "0.1.80"
axum = "0.7.7"
chrono = "0.4.38"
clap = { version = "4.5.9", features = ["derive"] }
dotenvy = "0.15.0"
Expand All @@ -29,6 +30,10 @@ reqwest = { version = "0.12", features = ["json"] }
name = "nbd-cli"
path = "src/cli/main.rs"

[[bin]]
name = "nbd-api"
path = "src/api/main.rs"

[lib]
name = "nbd"
path = "src/lib.rs"
28 changes: 28 additions & 0 deletions src/api/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![allow(dead_code)]
use axum::{routing::get, Router};

#[tokio::main]

async fn main() {
// build our application with a single route
let app = Router::new().route("/ok", get(ok));

// run our app with hyper, listening globally on port 8080
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app).await.unwrap();
}

async fn ok() -> String {
"ok".to_string()
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_ok_endpoint() {
let response = ok().await;
assert_eq!(response, "ok");
}
}
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod main;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod api;
pub mod db;
pub mod models;
pub mod utils;

0 comments on commit b77bfd9

Please sign in to comment.