Skip to content

Commit

Permalink
Add testing zone within main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMcCormickJr committed Dec 2, 2024
1 parent fadd627 commit 4202702
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 5 deletions.
81 changes: 81 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rocket = "0.5.1"
rocket = { version = "0.5.1", features = ["tls",] }
3 changes: 3 additions & 0 deletions requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ All authentication-related data, and all non-public user profile data, must be p
## Database
This app must use MariaDB with its TDE feature.

## Testing

This project aspires to align with both test-driven development (TDD) as well as the "Rugged" software principles:
46 changes: 42 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// main.rs



#![forbid(unsafe_code)]

#[macro_use] extern crate rocket;

use rocket::local::blocking::Client; // Import the blocking client for testing
use rocket::http::Status; // Import HTTP status for response checks

#[get("/")]
fn map_root() -> &'static str {
Expand All @@ -23,3 +21,43 @@ fn rocket() -> _ {
.mount("/", routes![map_root, map])
}

/*
_____ _ _ _____
|_ _|__ ___| |_(_)_ __ __ _ |__ /___ _ __ ___
| |/ _ \/ __| __| | '_ \ / _` | / // _ \| '_ \ / _ \
| | __/\__ \ |_| | | | | (_| | / /| (_) | | | | __/
|_|\___||___/\__|_|_| |_|\__, | /____\___/|_| |_|\___|
|___/
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
*/

#[cfg(test)] // Ensure this block is only included during testing
mod tests {
use super::*; // Import functions and routes from the main module

#[test]
fn test_map_root() {
let rocket = rocket::build()
.mount("/", routes![map_root]);
let client = Client::tracked(rocket).expect("valid rocket instance");
let response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(
response.into_string(),
Some("Map of Bartlesville recycling options".into())
);
}

#[test]
fn test_map_route() {
let rocket = rocket::build()
.mount("/", routes![map]);
let client = Client::tracked(rocket).expect("valid rocket instance");
let response = client.get("/map").dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(
response.into_string(),
Some("Map of Bartlesville recycling options".into())
);
}
}

0 comments on commit 4202702

Please sign in to comment.