upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/ngit_init.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-29 10:05:19 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-29 10:05:19 +0000
commit51c9541f8355fef82cab783b502ead9ea0f5cf19 (patch)
tree4221090676bc207f7553fa1d3f8e7b0d5af804b2 /tests/ngit_init.rs
parent1d6958d0ddfc2c3c73df4f6928704e94a9526ff5 (diff)
test(init): remove maintainers.yaml from tests
as creation by default was removed in 9bee5f12efa5ed751468c68073c9122e12c22b5f
Diffstat (limited to 'tests/ngit_init.rs')
-rw-r--r--tests/ngit_init.rs185
1 files changed, 0 insertions, 185 deletions
diff --git a/tests/ngit_init.rs b/tests/ngit_init.rs
index 4302524..7d1fb55 100644
--- a/tests/ngit_init.rs
+++ b/tests/ngit_init.rs
@@ -11,14 +11,6 @@ fn expect_msgs_first(p: &mut CliTester) -> Result<()> {
11 Ok(()) 11 Ok(())
12} 12}
13 13
14fn expect_msgs_after(p: &mut CliTester) -> Result<()> {
15 p.expect_after_whitespace("maintainers.yaml created. commit and push.\r\n")?;
16 p.expect(
17 "this optional file helps in identifying who the maintainers are over time through the commit history\r\n",
18 )?;
19 Ok(())
20}
21
22fn get_cli_args() -> Vec<&'static str> { 14fn get_cli_args() -> Vec<&'static str> {
23 vec![ 15 vec![
24 "--nsec", 16 "--nsec",
@@ -194,182 +186,6 @@ mod when_repo_not_previously_claimed {
194 } 186 }
195 } 187 }
196 188
197 mod yaml_file {
198 use std::{fs, io::Read};
199
200 use super::*;
201
202 async fn async_run_test() -> Result<()> {
203 let git_repo = prep_git_repo()?;
204 // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57)
205 let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = (
206 Relay::new(
207 8051,
208 None,
209 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
210 relay.respond_events(
211 client_id,
212 &subscription_id,
213 &vec![
214 generate_test_key_1_metadata_event("fred"),
215 generate_test_key_1_relay_list_event(),
216 ],
217 )?;
218 Ok(())
219 }),
220 ),
221 Relay::new(8052, None, None),
222 Relay::new(8053, None, None),
223 Relay::new(8055, None, None),
224 Relay::new(8056, None, None),
225 Relay::new(8057, None, None),
226 );
227
228 // // check relay had the right number of events
229 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
230 let mut p = cli_tester_init(&git_repo);
231 p.expect_end_eventually()?;
232
233 let yaml_path = git_repo.dir.join("maintainers.yaml");
234
235 assert!(yaml_path.exists());
236
237 let mut file = fs::File::open(yaml_path).expect("no such file");
238 let mut file_contents = "".to_string();
239 let _ = file.read_to_string(&mut file_contents);
240
241 for p in [51, 52, 53, 55, 56, 57] {
242 relay::shutdown_relay(8000 + p)?;
243 }
244 assert_eq!(
245 file_contents,
246 format!(
247 "\
248 identifier: example-identifier\n\
249 maintainers:\n\
250 - {TEST_KEY_1_NPUB}\n\
251 relays:\n\
252 - ws://localhost:8055\n\
253 - ws://localhost:8056\n\
254 "
255 ),
256 );
257 Ok(())
258 });
259
260 // launch relay
261 let _ = join!(
262 r51.listen_until_close(),
263 r52.listen_until_close(),
264 r53.listen_until_close(),
265 r55.listen_until_close(),
266 r56.listen_until_close(),
267 r57.listen_until_close(),
268 );
269 cli_tester_handle.join().unwrap()?;
270 Ok(())
271 }
272
273 #[tokio::test]
274 #[serial]
275 async fn contains_identifier_maintainers_and_relays() -> Result<()> {
276 async_run_test().await
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("failed to 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 }
370 }
371 }
372
373 mod git_config_updated { 189 mod git_config_updated {
374 190
375 use nostr::nips::nip01::Coordinate; 191 use nostr::nips::nip01::Coordinate;
@@ -678,7 +494,6 @@ mod when_repo_not_previously_claimed {
678 ], 494 ],
679 1, 495 1,
680 )?; 496 )?;
681 expect_msgs_after(&mut p)?;
682 p.expect_end()?; 497 p.expect_end()?;
683 for p in [51, 52, 53, 55, 56, 57] { 498 for p in [51, 52, 53, 55, 56, 57] {
684 relay::shutdown_relay(8000 + p)?; 499 relay::shutdown_relay(8000 + p)?;