11use crate :: entity_manager:: server:: EntityStoreResponse ;
2+ use crate :: entity_manager:: tests:: model:: Action ;
3+ use crate :: entity_manager:: tests:: model:: Command ;
4+ use crate :: entity_manager:: tests:: model:: Commands ;
5+ use crate :: entity_manager:: tests:: model:: Protocol :: MQTT ;
26use proptest:: proptest;
37use std:: collections:: HashSet ;
48use tedge_actors:: Server ;
@@ -14,6 +18,20 @@ async fn new_entity_store() {
1418 )
1519}
1620
21+ #[ tokio:: test]
22+ async fn removing_an_unknown_child_using_mqtt ( ) {
23+ let registrations = vec ! [
24+ // tedge mqtt pub -r te/device/a// ''
25+ Command {
26+ protocol: MQTT ,
27+ action: Action :: RemDevice {
28+ topic: "a" . to_string( ) ,
29+ } ,
30+ } ,
31+ ] ;
32+ check_registrations ( Commands ( registrations) ) . await
33+ }
34+
1735proptest ! {
1836 //#![proptest_config(proptest::prelude::ProptestConfig::with_cases(1000))]
1937 #[ test]
@@ -22,40 +40,40 @@ proptest! {
2240 . enable_all( )
2341 . build( )
2442 . unwrap( )
25- . block_on( async {
26- let ( mut entity_store, _mqtt_output) = entity:: server( "device-under-test" ) ;
27- let mut state = model:: State :: new( ) ;
28-
29- for model:: Command { protocol, action} in registrations. 0 {
30- let expected_updates = state. apply( protocol, action. clone( ) ) ;
31- let actual_updates = match entity_store. handle( ( protocol, action) . into( ) ) . await {
32- EntityStoreResponse :: Create ( Ok ( registered_entities) ) => {
33- registered_entities
34- . iter( )
35- . map( |registered_entity| registered_entity. reg_message. topic_id. clone( ) )
36- . collect( )
37- } ,
38- EntityStoreResponse :: Delete ( actual_updates) => HashSet :: from_iter( actual_updates) ,
39- _ => HashSet :: new( ) ,
40- } ;
41- assert_eq!( actual_updates, expected_updates) ;
42- }
43+ . block_on( check_registrations( registrations) )
44+ }
45+ }
46+
47+ async fn check_registrations ( registrations : Commands ) {
48+ let ( mut entity_store, _mqtt_output) = entity:: server ( "device-under-test" ) ;
49+ let mut state = model:: State :: new ( ) ;
50+
51+ for Command { protocol, action } in registrations. 0 {
52+ let expected_updates = state. apply ( protocol, action. clone ( ) ) ;
53+ let actual_updates = match entity_store. handle ( ( protocol, action) . into ( ) ) . await {
54+ EntityStoreResponse :: Create ( Ok ( registered_entities) ) => registered_entities
55+ . iter ( )
56+ . map ( |registered_entity| registered_entity. reg_message . topic_id . clone ( ) )
57+ . collect ( ) ,
58+ EntityStoreResponse :: Delete ( actual_updates) => HashSet :: from_iter ( actual_updates) ,
59+ _ => HashSet :: new ( ) ,
60+ } ;
61+ assert_eq ! ( actual_updates, expected_updates) ;
62+ }
4363
44- let mut registered_topics : Vec <_> = entity_store. entity_topic_ids( ) . collect( ) ;
45- registered_topics. sort_by( |a, b| a. as_ref( ) . cmp( b. as_ref( ) ) ) ;
64+ let mut registered_topics: Vec < _ > = entity_store. entity_topic_ids ( ) . collect ( ) ;
65+ registered_topics. sort_by ( |a, b| a. as_ref ( ) . cmp ( b. as_ref ( ) ) ) ;
4666
47- let mut expected_topics : Vec <_> = state. entity_topic_ids( ) . collect( ) ;
48- expected_topics. sort_by( |a, b| a. as_ref( ) . cmp( b. as_ref( ) ) ) ;
67+ let mut expected_topics: Vec < _ > = state. entity_topic_ids ( ) . collect ( ) ;
68+ expected_topics. sort_by ( |a, b| a. as_ref ( ) . cmp ( b. as_ref ( ) ) ) ;
4969
50- assert_eq!( registered_topics, expected_topics) ;
70+ assert_eq ! ( registered_topics, expected_topics) ;
5171
52- for topic in registered_topics {
53- let registered = entity_store. get( topic) . unwrap( ) ;
54- let ( entity_type, parent, _) = state. get( topic) . unwrap( ) ;
55- assert_eq!( & registered. r#type, entity_type) ;
56- assert_eq!( registered. parent. as_ref( ) , parent. as_ref( ) ) ;
57- }
58- } )
72+ for topic in registered_topics {
73+ let registered = entity_store. get ( topic) . unwrap ( ) ;
74+ let ( entity_type, parent, _) = state. get ( topic) . unwrap ( ) ;
75+ assert_eq ! ( & registered. r#type, entity_type) ;
76+ assert_eq ! ( registered. parent. as_ref( ) , parent. as_ref( ) ) ;
5977 }
6078}
6179
0 commit comments