Created
May 15, 2020 22:04
-
-
Save wontheone1/4e7df5fcc45a8285ea1b402627783a03 to your computer and use it in GitHub Desktop.
main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use actix_web::{web, App, HttpResponse, HttpServer, Responder}; | |
async fn index() -> impl Responder { | |
HttpResponse::Ok().body("Hello world!") | |
} | |
async fn index2() -> impl Responder { | |
HttpResponse::Ok().body("Hello world again!") | |
} | |
#[actix_rt::main] | |
async fn main() -> std::io::Result<()> { | |
HttpServer::new(|| { | |
App::new() | |
.route("/", web::get().to(index)) | |
.route("/again", web::get().to(index2)) | |
}) | |
.bind("127.0.0.1:8088")? | |
.run() | |
.await | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
use actix_web::{http}; | |
#[actix_rt::test] | |
async fn test_index_status_code() { | |
let resp = index().await; | |
assert_eq!(resp.status(), http::StatusCode::OK); | |
} | |
#[actix_rt::test] | |
async fn test_index_body() { | |
let resp = index().await; | |
let (body, mut resp) = resp.take_body().into_future().await; | |
assert_eq!(body, "moi"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment