@@ -296,193 +296,3 @@ async fn spawn(engine: nu::Engine, store: Store, task: GeneratorTask) {
296296 . unwrap ( ) ;
297297 } ) ;
298298}
299-
300- #[ cfg( test) ]
301- mod tests {
302- use super :: * ;
303- use tempfile:: TempDir ;
304-
305- use crate :: store:: ZERO_CONTEXT ;
306-
307- fn setup_test_env ( ) -> ( Store , nu:: Engine , Frame ) {
308- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
309- let store = Store :: new ( temp_dir. into_path ( ) ) ;
310- let engine = nu:: Engine :: new ( ) . unwrap ( ) ;
311- let ctx = store
312- . append ( Frame :: builder ( "xs.context" , ZERO_CONTEXT ) . build ( ) )
313- . unwrap ( ) ;
314- ( store, engine, ctx)
315- }
316-
317- #[ tokio:: test]
318- async fn test_serve_basic ( ) {
319- let ( store, engine, ctx) = setup_test_env ( ) ;
320-
321- {
322- let store = store. clone ( ) ;
323- let _ = tokio:: spawn ( async move {
324- serve ( store, engine) . await . unwrap ( ) ;
325- } ) ;
326- }
327-
328- let frame_generator = store
329- . append (
330- Frame :: builder ( "toml.spawn" , ctx. id )
331- . maybe_hash (
332- store
333- . cas_insert ( r#"^tail -n+0 -F Cargo.toml | lines"# )
334- . await
335- . ok ( ) ,
336- )
337- . build ( ) ,
338- )
339- . unwrap ( ) ;
340-
341- let options = ReadOptions :: builder ( )
342- . context_id ( ctx. id )
343- . follow ( FollowOption :: On )
344- . tail ( true )
345- . build ( ) ;
346- let mut recver = store. read ( options) . await ;
347-
348- let frame = recver. recv ( ) . await . unwrap ( ) ;
349- assert_eq ! ( frame. topic, "toml.start" . to_string( ) ) ;
350-
351- let frame = recver. recv ( ) . await . unwrap ( ) ;
352- assert_eq ! ( frame. topic, "toml.recv" . to_string( ) ) ;
353- let meta = frame. meta . unwrap ( ) ;
354- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
355- let content = store. cas_read ( & frame. hash . unwrap ( ) ) . await . unwrap ( ) ;
356- assert_eq ! ( std:: str :: from_utf8( & content) . unwrap( ) , "[package]" ) ;
357-
358- let frame = recver. recv ( ) . await . unwrap ( ) ;
359- assert_eq ! ( frame. topic, "toml.recv" . to_string( ) ) ;
360- let meta = frame. meta . unwrap ( ) ;
361- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
362- let content = store. cas_read ( & frame. hash . unwrap ( ) ) . await . unwrap ( ) ;
363- assert_eq ! (
364- std:: str :: from_utf8( & content) . unwrap( ) ,
365- r#"name = "cross-stream""#
366- ) ;
367- }
368-
369- #[ tokio:: test]
370- async fn test_serve_duplex ( ) {
371- let ( store, engine, ctx) = setup_test_env ( ) ;
372-
373- {
374- let store = store. clone ( ) ;
375- let _ = tokio:: spawn ( async move {
376- serve ( store, engine) . await . unwrap ( ) ;
377- } ) ;
378- }
379-
380- let frame_generator = store
381- . append (
382- Frame :: builder ( "greeter.spawn" . to_string ( ) , ctx. id )
383- . maybe_hash ( store. cas_insert ( r#"each { |x| $"hi: ($x)" }"# ) . await . ok ( ) )
384- . meta ( serde_json:: json!( { "duplex" : true } ) )
385- . build ( ) ,
386- )
387- . unwrap ( ) ;
388-
389- let options = ReadOptions :: builder ( )
390- . follow ( FollowOption :: On )
391- . tail ( true )
392- . build ( ) ;
393- let mut recver = store. read ( options) . await ;
394-
395- let frame = recver. recv ( ) . await . unwrap ( ) ;
396- assert_eq ! ( frame. topic, "greeter.start" . to_string( ) ) ;
397-
398- let _ = store
399- . append (
400- Frame :: builder ( "greeter.send" , ctx. id )
401- . maybe_hash ( store. cas_insert ( r#"henry"# ) . await . ok ( ) )
402- . build ( ) ,
403- )
404- . unwrap ( ) ;
405- assert_eq ! (
406- recver. recv( ) . await . unwrap( ) . topic,
407- "greeter.send" . to_string( )
408- ) ;
409-
410- // assert we see a reaction from the generator
411- let frame = recver. recv ( ) . await . unwrap ( ) ;
412- assert_eq ! ( frame. topic, "greeter.recv" . to_string( ) ) ;
413- let meta = frame. meta . unwrap ( ) ;
414- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
415- let content = store. cas_read ( & frame. hash . unwrap ( ) ) . await . unwrap ( ) ;
416- assert_eq ! ( std:: str :: from_utf8( & content) . unwrap( ) , "hi: henry" ) ;
417- }
418-
419- #[ tokio:: test]
420- async fn test_serve_compact ( ) {
421- let ( store, engine, ctx) = setup_test_env ( ) ;
422-
423- let _ = store
424- . append (
425- Frame :: builder ( "toml.spawn" , ctx. id )
426- . maybe_hash (
427- store
428- . cas_insert ( r#"^tail -n+0 -F Cargo.toml | lines"# )
429- . await
430- . ok ( ) ,
431- )
432- . build ( ) ,
433- )
434- . unwrap ( ) ;
435-
436- // replaces the previous generator
437- let frame_generator = store
438- . append (
439- Frame :: builder ( "toml.spawn" , ctx. id )
440- . maybe_hash (
441- store
442- . cas_insert ( r#"^tail -n +2 -F Cargo.toml | lines"# )
443- . await
444- . ok ( ) ,
445- )
446- . build ( ) ,
447- )
448- . unwrap ( ) ;
449-
450- let options = ReadOptions :: builder ( )
451- . follow ( FollowOption :: On )
452- . tail ( true )
453- . build ( ) ;
454- let mut recver = store. read ( options) . await ;
455-
456- {
457- let store = store. clone ( ) ;
458- let _ = tokio:: spawn ( async move {
459- serve ( store, engine) . await . unwrap ( ) ;
460- } ) ;
461- }
462-
463- let frame = recver. recv ( ) . await . unwrap ( ) ;
464- assert_eq ! ( frame. topic, "toml.start" . to_string( ) ) ;
465- let meta = frame. meta . unwrap ( ) ;
466- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
467-
468- let frame = recver. recv ( ) . await . unwrap ( ) ;
469- assert_eq ! ( frame. topic, "toml.recv" . to_string( ) ) ;
470- let meta = frame. meta . unwrap ( ) ;
471- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
472- let content = store. cas_read ( & frame. hash . unwrap ( ) ) . await . unwrap ( ) ;
473- assert_eq ! (
474- std:: str :: from_utf8( & content) . unwrap( ) ,
475- r#"name = "cross-stream""#
476- ) ;
477-
478- let frame = recver. recv ( ) . await . unwrap ( ) ;
479- assert_eq ! ( frame. topic, "toml.recv" . to_string( ) ) ;
480- let meta = frame. meta . unwrap ( ) ;
481- assert_eq ! ( meta[ "source_id" ] , frame_generator. id. to_string( ) ) ;
482- let content = store. cas_read ( & frame. hash . unwrap ( ) ) . await . unwrap ( ) ;
483- assert_eq ! (
484- std:: str :: from_utf8( & content) . unwrap( ) ,
485- r#"edition = "2021""#
486- ) ;
487- }
488- }
0 commit comments