diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-10 08:01:07 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-10 08:01:07 +0200 |
| commit | e3fdf12d472b24a9a91a0bdebe667b86797b2483 (patch) | |
| tree | e6b6863318f318b93cece86b4351473b4432a83b | |
| parent | c8d286239ef0d14a985cdcc26e0eda57098a5db1 (diff) | |
| download | lambda-nantes-e3fdf12d472b24a9a91a0bdebe667b86797b2483.tar.gz | |
Add name to client registration
| -rw-r--r-- | rust/src/web.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/rust/src/web.rs b/rust/src/web.rs index 3b9fc9e..2b540c2 100644 --- a/rust/src/web.rs +++ b/rust/src/web.rs @@ -16,6 +16,7 @@ use lambda::parser::parse; #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] struct Registration { url: String, + name: String, } trait AppState: Send + Sync { @@ -32,6 +33,7 @@ enum RegistrationResult { struct Client { id: Uuid, url: String, + name: String, grade: u8, runner: TestRunner, results: Vec<TestResult>, @@ -46,7 +48,7 @@ enum TestResult { } impl Client { - fn new(url: String) -> Self { + fn new(url: String, name: String) -> Self { let id = Uuid::new_v4(); let runner = TestRunner::new_with_rng( Config::default(), @@ -55,6 +57,7 @@ impl Client { Self { id, url, + name, grade: 1, runner, results: Vec::new(), @@ -146,7 +149,7 @@ impl AppState for State { url: registration.url.clone(), } } else { - let client = Client::new(registration.url.clone()); + let client = Client::new(registration.url.clone(), registration.name.clone()); let id = client.id.to_string(); let client_ref = Arc::new(Mutex::new(client)); let client_s = client_ref.clone(); @@ -303,7 +306,10 @@ mod app_tests { let url = "http://192.168.1.1".to_string(); let req = test::TestRequest::post() .uri("/register") - .set_json(Registration { url: url.clone() }) + .set_json(Registration { + url: url.clone(), + name: "foo".to_string(), + }) .insert_header(ContentType::json()) .to_request(); @@ -335,7 +341,10 @@ mod app_tests { let req = test::TestRequest::post() .uri("/register") - .set_json(Registration { url: url.clone() }) + .set_json(Registration { + url: url.clone(), + name: "foo".to_string(), + }) .insert_header(ContentType::json()) .to_request(); @@ -371,6 +380,7 @@ mod app_tests { async fn app_does_not_register_same_url_twice() { let mut app_state = State::new(); let registration = Registration { + name: "foo".to_string(), url: "http://1.2.3.4".to_string(), }; @@ -386,7 +396,7 @@ mod app_tests { } fn client() -> Client { - Client::new("http://1.2.3.4".to_string()) + Client::new("http://1.2.3.4".to_string(), "foo".to_string()) } #[test] |
