-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because of issue rust-lang/rust#46379
- Loading branch information
Bastian Oppermann
committed
Jul 25, 2024
1 parent
3e73463
commit b63ab6e
Showing
12 changed files
with
164 additions
and
192 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"cSpell.words": ["bukkit", "bungeecord"] | ||
"cSpell.words": ["bukkit", "bungeecord", "testcontainer"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,17 @@ | ||
use actix_web::{get, post, web, App, HttpServer, Responder}; | ||
use data_processor::{charts::simple_pie::SimplePie, submit_data_schema::SubmitDataSchema}; | ||
|
||
#[get("/")] | ||
async fn index() -> impl Responder { | ||
web::Json(SimplePie { | ||
value: String::from("Test"), | ||
}) | ||
} | ||
|
||
#[post("/{software_url}")] | ||
async fn handle_data_submission( | ||
_software_url: web::Path<String>, | ||
_data: web::Json<SubmitDataSchema>, | ||
) -> impl Responder { | ||
web::Json(SimplePie { | ||
value: String::from("Test"), | ||
}) | ||
} | ||
use actix_web::{web, App, HttpServer}; | ||
use data_processor::{handle_data_submission, index}; | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
HttpServer::new(|| App::new().service(index).service(handle_data_submission)) | ||
.bind(("127.0.0.1", 8080))? | ||
.run() | ||
.await | ||
} | ||
let redis = redis::Client::open("redis://127.0.0.1:6379").unwrap(); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use actix_web::{http::header::ContentType, test, App}; | ||
use serde_json::json; | ||
|
||
use super::*; | ||
|
||
#[actix_web::test] | ||
async fn test_submit_data() { | ||
let app = test::init_service(App::new().service(handle_data_submission)).await; | ||
let req = test::TestRequest::post() | ||
.uri("/bukkit") | ||
.insert_header(ContentType::json()) | ||
.set_payload( | ||
json!({ | ||
"playerAmount": 0, | ||
"onlineMode": 1, | ||
"bukkitVersion": "1.21-38-1f5db50 (MC: 1.21)", | ||
"bukkitName": "Paper", | ||
"javaVersion": "21.0.2", | ||
"osName": "Windows 11", | ||
"osArch": "amd64", | ||
"osVersion": "10.0", | ||
"coreCount": 24, | ||
"service": { | ||
"pluginVersion": "1.0.0-SNAPSHOT", | ||
"id": 1234, | ||
"customCharts": [ | ||
{ | ||
"chartId": "chart_id", | ||
"data": { | ||
"value": "My value" | ||
} | ||
} | ||
] | ||
}, | ||
"serverUUID": "7386d410-f71e-447c-b356-ee809c7db098", | ||
"metricsVersion": "3.0.2" | ||
}) | ||
.to_string(), | ||
) | ||
.to_request(); | ||
|
||
let resp = test::call_service(&app, req).await; | ||
assert!(resp.status().is_success()); | ||
} | ||
|
||
#[actix_web::test] | ||
async fn test_index_get() { | ||
let app = test::init_service(App::new().service(index)).await; | ||
let req = test::TestRequest::default() | ||
.insert_header(ContentType::plaintext()) | ||
.to_request(); | ||
let resp = test::call_service(&app, req).await; | ||
assert!(resp.status().is_success()); | ||
} | ||
|
||
#[actix_web::test] | ||
async fn test_index_post() { | ||
let app = test::init_service(App::new().service(index)).await; | ||
let req = test::TestRequest::post().uri("/").to_request(); | ||
let resp = test::call_service(&app, req).await; | ||
assert!(resp.status().is_client_error()); | ||
} | ||
HttpServer::new(move || { | ||
App::new() | ||
.app_data(web::Data::new(redis.clone())) | ||
.service(index) | ||
.service(handle_data_submission) | ||
}) | ||
.bind(("127.0.0.1", 1234))? | ||
.run() | ||
.await | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod redis_testcontainer; | ||
pub mod test_environment; |
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
Oops, something went wrong.