Skip to content

Commit

Permalink
Add test script
Browse files Browse the repository at this point in the history
  • Loading branch information
rashed091 committed Nov 24, 2023
1 parent 79c2855 commit a704318
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ mod services;

use controllers::user_controller;
use dotenv::dotenv;
use salvo::cors::Cors;
use salvo::http::Method;
use salvo::logging::Logger;
use salvo::prelude::*;
use std::env;

Expand All @@ -14,6 +17,11 @@ async fn health() -> &'static str {
"I'm alive"
}

#[handler]
async fn index() -> &'static str {
"Welcome to rustful-service"
}


#[tokio::main]
async fn main() {
Expand All @@ -26,7 +34,13 @@ async fn main() {
let port = env::var("PORT").expect("PORT is not set in .env file");
let server_url = format!("{host}:{port}");

let router = Router::new()
let cors = Cors::new()
.allow_methods(vec![Method::GET, Method::POST, Method::DELETE])
.into_handler();


let router = Router::with_hoop(cors).hoop(Logger::new())
.get(index)
.push(Router::with_path("/healthz").get(health))
.push(Router::with_path("/users")
.get(user_controller::get_all_users)
Expand Down
24 changes: 24 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -ex

res=$(curl -s -X POST http://127.0.0.1:5001/users -H "Content-Type: application/json" \
-d '{"name": "Rashed", "age": "27"}')

echo "${res}"

# lastid="$(echo "${res}" | jq ".id")"

# can get it individually
# curl -s -X GET "http://127.0.0.1:5001/users/${lastid}"

# post not published yet
# curl -s -X GET http://127.0.0.1:5001/users | grep -v "${lastid}"

# publish
# curl -s -X PUT "http://127.0.0.1:5001/users/${lastid}"

# post now published
# curl -s -X GET http://127.0.0.1:5001/users | grep "${lastid}"

# delete post
# curl -s -X DELETE "http://127.0.0.1:5001/users/${lastid}"

0 comments on commit a704318

Please sign in to comment.