This commit is contained in:
parent
8660b42cfb
commit
da406d4943
9 changed files with 2113 additions and 0 deletions
20
.forgejo/workflows/main.yml
Normal file
20
.forgejo/workflows/main.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
name: Pipeline main branch
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest # Or other appropriate runner
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4 # Checkout the repository
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -
|
||||||
|
source $HOME/.cargo/env
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --verbose
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
2001
Cargo.lock
generated
Normal file
2001
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
38
Cargo.toml
Normal file
38
Cargo.toml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
[package]
|
||||||
|
name = "rust_app"
|
||||||
|
version.workspace = true
|
||||||
|
authors.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["crates/server"]
|
||||||
|
|
||||||
|
[workspace.package]
|
||||||
|
authors = ["continuist <continuist02@gmail.com>"]
|
||||||
|
version = "0.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
rust-version = "1.81.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "web"
|
||||||
|
path = "src/bin/web.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = { version = "0.8.3" }
|
||||||
|
reqwest = { version = "0.12.15" }
|
||||||
|
tokio = { version = "1.26", features = ["full"] }
|
||||||
|
axum-test = "17.3.0"
|
||||||
|
|
||||||
|
|
||||||
|
server = "=0.0.0"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
server = { path = "crates/server" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
opt-level = 3
|
||||||
|
codegen-units = 1
|
||||||
|
strip = true
|
11
crates/server/Cargo.toml
Normal file
11
crates/server/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "server"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
axum = { version = "0.8.3" }
|
||||||
|
tokio = { version = "1.26", features = ["full"] }
|
1
crates/server/src/lib.rs
Normal file
1
crates/server/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod server;
|
12
crates/server/src/server.rs
Normal file
12
crates/server/src/server.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use axum::{
|
||||||
|
routing::get,
|
||||||
|
Router,
|
||||||
|
};
|
||||||
|
|
||||||
|
async fn hello_world() -> &'static str {
|
||||||
|
"Hello, World!"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_app() -> Router {
|
||||||
|
Router::new().route("/", get(hello_world))
|
||||||
|
}
|
11
src/bin/web.rs
Normal file
11
src/bin/web.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use server::server::create_app;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
|
||||||
|
|
||||||
|
let app = create_app().await;
|
||||||
|
|
||||||
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
}
|
18
tests/test_hello.rs
Normal file
18
tests/test_hello.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_hello_route() {
|
||||||
|
use axum_test::TestServer;
|
||||||
|
use server::server::create_app;
|
||||||
|
|
||||||
|
// Create a TestServer with your application
|
||||||
|
let app = create_app().await;
|
||||||
|
let server = TestServer::new(app).unwrap();
|
||||||
|
|
||||||
|
// Make a request to the `/hello` route
|
||||||
|
let response = server.get("/").await;
|
||||||
|
|
||||||
|
// Assert that the status code is OK (200)
|
||||||
|
response.assert_status_ok();
|
||||||
|
|
||||||
|
// Assert that the response body contains the expected text
|
||||||
|
response.assert_text("Hello, World!");
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue