diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-25 08:26:26 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-25 09:04:01 +0100 |
| commit | f4a4220cd4691e562d0a849ad8900bf54411363b (patch) | |
| tree | 77b808d89ef41ef98987fa143bf6b5546b2d56a6 /tests | |
| parent | adc9b8d43d208178269d0f1178255d933ae1c4a5 (diff) | |
fix(init): add missing identifier to yaml
add missing or updated identifier to maintainers.yaml
as we were not checking whether it has changed or added
also update if relays do not match
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/init.rs | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/tests/init.rs b/tests/init.rs index afd3848..896cef8 100644 --- a/tests/init.rs +++ b/tests/init.rs | |||
| @@ -272,9 +272,101 @@ mod when_repo_not_previously_claimed { | |||
| 272 | 272 | ||
| 273 | #[tokio::test] | 273 | #[tokio::test] |
| 274 | #[serial] | 274 | #[serial] |
| 275 | async fn contains_maintainers_and_relays() -> Result<()> { | 275 | async fn contains_identifier_maintainers_and_relays() -> Result<()> { |
| 276 | async_run_test().await?; | 276 | async_run_test().await |
| 277 | Ok(()) | 277 | } |
| 278 | mod updates_existing_with_missing_identifier { | ||
| 279 | use std::io::Write; | ||
| 280 | |||
| 281 | use super::*; | ||
| 282 | async fn async_run_test() -> Result<()> { | ||
| 283 | let git_repo = prep_git_repo()?; | ||
| 284 | // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57) | ||
| 285 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 286 | Relay::new( | ||
| 287 | 8051, | ||
| 288 | None, | ||
| 289 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 290 | relay.respond_events( | ||
| 291 | client_id, | ||
| 292 | &subscription_id, | ||
| 293 | &vec![ | ||
| 294 | generate_test_key_1_metadata_event("fred"), | ||
| 295 | generate_test_key_1_relay_list_event(), | ||
| 296 | ], | ||
| 297 | )?; | ||
| 298 | Ok(()) | ||
| 299 | }), | ||
| 300 | ), | ||
| 301 | Relay::new(8052, None, None), | ||
| 302 | Relay::new(8053, None, None), | ||
| 303 | Relay::new(8055, None, None), | ||
| 304 | Relay::new(8056, None, None), | ||
| 305 | Relay::new(8057, None, None), | ||
| 306 | ); | ||
| 307 | |||
| 308 | // // check relay had the right number of events | ||
| 309 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 310 | let yaml_path = git_repo.dir.join("maintainers.yaml"); | ||
| 311 | let mut file = std::fs::File::create(&yaml_path) | ||
| 312 | .expect("cannot create maintainers.yaml file"); | ||
| 313 | write!( | ||
| 314 | file, | ||
| 315 | "\ | ||
| 316 | maintainers:\n\ | ||
| 317 | - {TEST_KEY_1_NPUB}\n\ | ||
| 318 | relays:\n\ | ||
| 319 | - ws://localhost:8055\n\ | ||
| 320 | - ws://localhost:8056\n\ | ||
| 321 | " | ||
| 322 | )?; | ||
| 323 | |||
| 324 | let mut p = cli_tester_init(&git_repo); | ||
| 325 | p.expect_end_eventually()?; | ||
| 326 | |||
| 327 | assert!(yaml_path.exists()); | ||
| 328 | |||
| 329 | let mut file = fs::File::open(yaml_path).expect("no such file"); | ||
| 330 | let mut file_contents = "".to_string(); | ||
| 331 | let _ = file.read_to_string(&mut file_contents); | ||
| 332 | |||
| 333 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 334 | relay::shutdown_relay(8000 + p)?; | ||
| 335 | } | ||
| 336 | assert_eq!( | ||
| 337 | file_contents, | ||
| 338 | format!( | ||
| 339 | "\ | ||
| 340 | identifier: example-identifier\n\ | ||
| 341 | maintainers:\n\ | ||
| 342 | - {TEST_KEY_1_NPUB}\n\ | ||
| 343 | relays:\n\ | ||
| 344 | - ws://localhost:8055\n\ | ||
| 345 | - ws://localhost:8056\n\ | ||
| 346 | " | ||
| 347 | ), | ||
| 348 | ); | ||
| 349 | Ok(()) | ||
| 350 | }); | ||
| 351 | |||
| 352 | // launch relay | ||
| 353 | let _ = join!( | ||
| 354 | r51.listen_until_close(), | ||
| 355 | r52.listen_until_close(), | ||
| 356 | r53.listen_until_close(), | ||
| 357 | r55.listen_until_close(), | ||
| 358 | r56.listen_until_close(), | ||
| 359 | r57.listen_until_close(), | ||
| 360 | ); | ||
| 361 | cli_tester_handle.join().unwrap()?; | ||
| 362 | Ok(()) | ||
| 363 | } | ||
| 364 | |||
| 365 | #[tokio::test] | ||
| 366 | #[serial] | ||
| 367 | async fn adds_missing_identifier() -> Result<()> { | ||
| 368 | async_run_test().await | ||
| 369 | } | ||
| 278 | } | 370 | } |
| 279 | } | 371 | } |
| 280 | 372 | ||