From fff331090034bb8140f66a3cd7441c96e7f5c070 Mon Sep 17 00:00:00 2001 From: adonia Date: Fri, 13 Sep 2024 16:47:17 +0800 Subject: [PATCH] fix: test data in unit test --- .../src/dev_server/addons/extensions.rs | 28 +-- .../addons/test_data_embed/app_manifest.json | 32 +++ .../test_data_embed/app_property.json} | 0 .../extension_addon_1_manifest.json | 0 .../extension_addon_2_manifest.json | 0 .../extension_addon_3_manifest.json | 0 .../src/dev_server/graphs/connections.rs | 36 +-- .../ten_manager/src/dev_server/graphs/mod.rs | 28 +-- .../src/dev_server/graphs/nodes.rs | 56 ++--- .../test_data_embed/app_manifest.json} | 0 .../graphs/test_data_embed/app_property.json | 67 ++++++ .../extension_addon_1_manifest.json | 36 ++- .../extension_addon_2_manifest.json | 54 ++++- .../extension_addon_3_manifest.json | 37 +++ .../app_manifest.json} | 0 .../app_property.json} | 0 .../extension_addon_1_manifest.json | 12 + .../extension_addon_2_manifest.json | 12 + .../input_data.json} | 0 .../src/dev_server/graphs/update.rs | 30 +-- .../src/dev_server/messages/compatible.rs | 213 ++---------------- .../extension_addon_1_manifest.json | 168 ++++++++------ .../extension_addon_2_manifest.json | 174 ++++++++------ .../src/dev_server/property/check.rs | 6 +- .../src/dev_server/property/dump.rs | 39 +--- ...pe_app_manifest.json => app_manifest.json} | 0 ...pe_app_property.json => app_property.json} | 0 ... => dump_property_success_input_data.json} | 0 28 files changed, 529 insertions(+), 499 deletions(-) create mode 100644 core/src/ten_manager/src/dev_server/addons/test_data_embed/app_manifest.json rename core/src/ten_manager/src/dev_server/{test_data_embed/large_response_source_app_property.json => addons/test_data_embed/app_property.json} (100%) rename core/src/ten_manager/src/dev_server/{ => addons}/test_data_embed/extension_addon_1_manifest.json (100%) rename core/src/ten_manager/src/dev_server/{ => addons}/test_data_embed/extension_addon_2_manifest.json (100%) rename core/src/ten_manager/src/dev_server/{ => addons}/test_data_embed/extension_addon_3_manifest.json (100%) rename core/src/ten_manager/src/dev_server/{test_data_embed/large_response_source_app_manifest.json => graphs/test_data_embed/app_manifest.json} (100%) create mode 100644 core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_property.json create mode 100644 core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_3_manifest.json rename core/src/ten_manager/src/dev_server/graphs/test_data_embed/{all_data_type_app_manifest.json => get_connections_have_all_data_type/app_manifest.json} (100%) rename core/src/ten_manager/src/dev_server/graphs/test_data_embed/{all_data_type_app_property.json => get_connections_have_all_data_type/app_property.json} (100%) create mode 100644 core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json create mode 100644 core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json rename core/src/ten_manager/src/dev_server/graphs/test_data_embed/{test_update_graph_success_input_data.json => update_graph_success/input_data.json} (100%) rename core/src/ten_manager/src/dev_server/property/test_data_embed/{all_data_type_app_manifest.json => app_manifest.json} (100%) rename core/src/ten_manager/src/dev_server/property/test_data_embed/{all_data_type_app_property.json => app_property.json} (100%) rename core/src/ten_manager/src/dev_server/property/test_data_embed/{test_dump_property_success_input_data.json => dump_property_success_input_data.json} (100%) diff --git a/core/src/ten_manager/src/dev_server/addons/extensions.rs b/core/src/ten_manager/src/dev_server/addons/extensions.rs index 4f136b8ca7..3ac3640dee 100644 --- a/core/src/ten_manager/src/dev_server/addons/extensions.rs +++ b/core/src/ten_manager/src/dev_server/addons/extensions.rs @@ -172,34 +172,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; diff --git a/core/src/ten_manager/src/dev_server/addons/test_data_embed/app_manifest.json b/core/src/ten_manager/src/dev_server/addons/test_data_embed/app_manifest.json new file mode 100644 index 0000000000..06ce9b2a97 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/addons/test_data_embed/app_manifest.json @@ -0,0 +1,32 @@ +{ + "type": "app", + "name": "test_get_addons", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.2.0" + }, + { + "type": "extension", + "name": "extension_addon_1", + "version": "0.1.0" + }, + { + "type": "extension", + "name": "extension_addon_2", + "version": "0.1.0" + }, + { + "type": "extension", + "name": "extension_addon_3", + "version": "0.1.0" + }, + { + "type": "extension_group", + "name": "default_extension_group", + "version": "0.1.0" + } + ] +} diff --git a/core/src/ten_manager/src/dev_server/test_data_embed/large_response_source_app_property.json b/core/src/ten_manager/src/dev_server/addons/test_data_embed/app_property.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data_embed/large_response_source_app_property.json rename to core/src/ten_manager/src/dev_server/addons/test_data_embed/app_property.json diff --git a/core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_1_manifest.json b/core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_1_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_1_manifest.json rename to core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_1_manifest.json diff --git a/core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_2_manifest.json b/core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_2_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_2_manifest.json rename to core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_2_manifest.json diff --git a/core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_3_manifest.json b/core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_3_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data_embed/extension_addon_3_manifest.json rename to core/src/ten_manager/src/dev_server/addons/test_data_embed/extension_addon_3_manifest.json diff --git a/core/src/ten_manager/src/dev_server/graphs/connections.rs b/core/src/ten_manager/src/dev_server/graphs/connections.rs index 36cab9199b..57c003d342 100644 --- a/core/src/ten_manager/src/dev_server/graphs/connections.rs +++ b/core/src/ten_manager/src/dev_server/graphs/connections.rs @@ -192,34 +192,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -288,18 +276,18 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("test_data_embed/all_data_type_app_manifest.json") + include_str!("test_data_embed/get_connections_have_all_data_type/app_manifest.json") .to_string(), - include_str!("test_data_embed/all_data_type_app_property.json") + include_str!("test_data_embed/get_connections_have_all_data_type/app_property.json") .to_string(), ), ( - include_str!("test_data_embed/extension_addon_1_manifest.json") + include_str!("test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("test_data_embed/extension_addon_2_manifest.json") + include_str!("test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), diff --git a/core/src/ten_manager/src/dev_server/graphs/mod.rs b/core/src/ten_manager/src/dev_server/graphs/mod.rs index d8b4ac59f5..77bf4c5492 100644 --- a/core/src/ten_manager/src/dev_server/graphs/mod.rs +++ b/core/src/ten_manager/src/dev_server/graphs/mod.rs @@ -98,34 +98,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; diff --git a/core/src/ten_manager/src/dev_server/graphs/nodes.rs b/core/src/ten_manager/src/dev_server/graphs/nodes.rs index 106d48b939..a9e72f22e7 100644 --- a/core/src/ten_manager/src/dev_server/graphs/nodes.rs +++ b/core/src/ten_manager/src/dev_server/graphs/nodes.rs @@ -375,34 +375,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -652,34 +640,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; diff --git a/core/src/ten_manager/src/dev_server/test_data_embed/large_response_source_app_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data_embed/large_response_source_app_manifest.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_manifest.json diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_property.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_property.json new file mode 100644 index 0000000000..ebe4b76dcc --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/app_property.json @@ -0,0 +1,67 @@ +{ + "_ten": { + "predefined_graphs": [ + { + "name": "0", + "auto_start": true, + "nodes": [ + { + "type": "extension", + "name": "extension_1", + "addon": "extension_addon_1", + "extension_group": "extension_group_1" + }, + { + "type": "extension", + "name": "extension_2", + "addon": "extension_addon_2", + "extension_group": "extension_group_1", + "property": { + "a": 1 + } + }, + { + "type": "extension", + "name": "extension_3", + "addon": "extension_addon_3", + "extension_group": "extension_group_1" + } + ], + "connections": [ + { + "extension_group": "extension_group_1", + "extension": "extension_1", + "cmd": [ + { + "name": "hello_world", + "dest": [ + { + "extension_group": "extension_group_1", + "extension": "extension_2" + } + ] + } + ] + } + ] + }, + { + "name": "addon_not_found", + "auto_start": false, + "nodes": [ + { + "type": "extension_group", + "name": "default", + "addon": "default_extension_group" + }, + { + "type": "extension", + "name": "extension_1", + "addon": "extension_addon_1_not_found", + "extension_group": "default" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_1_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_1_manifest.json index 5a5f9c7666..fa4ce727d0 100644 --- a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_1_manifest.json +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_1_manifest.json @@ -8,5 +8,39 @@ "name": "ten_runtime", "version": "0.2.0" } - ] + ], + "api": { + "cmd_out": [ + { + "name": "test_cmd", + "property": { + "test_property": { + "type": "int8" + } + } + }, + { + "name": "has_required", + "property": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "name": "has_required_mismatch", + "property": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + } } \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_2_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_2_manifest.json index 9ba2b76516..bd46c6379b 100644 --- a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_2_manifest.json +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_2_manifest.json @@ -8,5 +8,57 @@ "name": "ten_runtime", "version": "0.2.0" } - ] + ], + "api": { + "cmd_in": [ + { + "name": "test_cmd", + "property": { + "test_property": { + "type": "int32" + } + } + }, + { + "name": "another_test_cmd", + "property": { + "test_property": { + "type": "int8" + } + } + }, + { + "name": "has_required", + "property": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "name": "has_required_mismatch", + "property": { + "foo": { + "type": "string" + } + } + } + ], + "data_out": [ + { + "name": "data_has_required", + "property": { + "foo": { + "type": "int8" + } + }, + "required": [ + "foo" + ] + } + ] + } } \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_3_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_3_manifest.json new file mode 100644 index 0000000000..aee78b3204 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_3_manifest.json @@ -0,0 +1,37 @@ +{ + "type": "extension", + "name": "extension_addon_3", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.2.0" + } + ], + "api": { + "cmd_in": [ + { + "name": "test_cmd", + "property": { + "test_property": { + "type": "string" + } + } + } + ], + "data_in": [ + { + "name": "data_has_required", + "property": { + "foo": { + "type": "int8" + } + }, + "required": [ + "foo" + ] + } + ] + } +} \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/all_data_type_app_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/app_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/graphs/test_data_embed/all_data_type_app_manifest.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/app_manifest.json diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/all_data_type_app_property.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/app_property.json similarity index 100% rename from core/src/ten_manager/src/dev_server/graphs/test_data_embed/all_data_type_app_property.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/app_property.json diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json new file mode 100644 index 0000000000..5a5f9c7666 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json @@ -0,0 +1,12 @@ +{ + "type": "extension", + "name": "extension_addon_1", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.2.0" + } + ] +} \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json new file mode 100644 index 0000000000..9ba2b76516 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json @@ -0,0 +1,12 @@ +{ + "type": "extension", + "name": "extension_addon_2", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.2.0" + } + ] +} \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data_embed/test_update_graph_success_input_data.json b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/update_graph_success/input_data.json similarity index 100% rename from core/src/ten_manager/src/dev_server/graphs/test_data_embed/test_update_graph_success_input_data.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/update_graph_success/input_data.json diff --git a/core/src/ten_manager/src/dev_server/graphs/update.rs b/core/src/ten_manager/src/dev_server/graphs/update.rs index d1b990d333..3edddabee0 100644 --- a/core/src/ten_manager/src/dev_server/graphs/update.rs +++ b/core/src/ten_manager/src/dev_server/graphs/update.rs @@ -196,34 +196,22 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_3_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -245,7 +233,7 @@ mod tests { .await; let input_data: Value = serde_json::from_str(include_str!( - "test_data_embed/test_update_graph_success_input_data.json" + "test_data_embed/update_graph_success/input_data.json" )) .unwrap(); diff --git a/core/src/ten_manager/src/dev_server/messages/compatible.rs b/core/src/ten_manager/src/dev_server/messages/compatible.rs index 9f2d09dada..3f4bb1f240 100644 --- a/core/src/ten_manager/src/dev_server/messages/compatible.rs +++ b/core/src/ten_manager/src/dev_server/messages/compatible.rs @@ -325,34 +325,17 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -422,34 +405,17 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -501,34 +467,17 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -598,34 +547,17 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_1_manifest.json") + .to_string(), "{}".to_string(), ), ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -684,103 +616,6 @@ mod tests { assert_eq!(compatibles.data, expected_compatibles); } - #[actix_web::test] - async fn test_get_compatible_messages_data_has_required_success() { - let mut dev_server_state = DevServerState { - base_dir: None, - all_pkgs: None, - tman_config: TmanConfig::default(), - }; - - let all_pkgs_json = vec![ - ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ]; - - let inject_ret = - inject_all_pkgs_for_mock(&mut dev_server_state, all_pkgs_json); - assert!(inject_ret.is_ok()); - - let dev_server_state = Arc::new(RwLock::new(dev_server_state)); - - let app = test::init_service( - App::new().app_data(web::Data::new(dev_server_state)).route( - "/api/dev-server/v1/messages/compatible", - web::post().to(get_compatible_messages), - ), - ) - .await; - - // Define input data. - let input_data = json!({ - "app": "localhost", - "graph": "0", - "extension_group": "extension_group_1", - "extension": "extension_2", - "msg_type": "data", - "msg_direction": "out", - "msg_name": "data_has_required" - }); - - // Send request to the test server. - let req = test::TestRequest::post() - .uri("/api/dev-server/v1/messages/compatible") - .set_json(&input_data) - .to_request(); - - // Call the service and get the response. - let resp = test::call_service(&app, req).await; - assert!(resp.status().is_success()); - - let body = test::read_body(resp).await; - let body_str = std::str::from_utf8(&body).unwrap(); - - let compatibles: ApiResponse> = - serde_json::from_str(body_str).unwrap(); - - let expected_compatibles = vec![DevServerCompatibleMsg { - app: default_app_loc(), - extension_group: "extension_group_1".to_string(), - extension: "extension_3".to_string(), - msg_type: MsgType::Data, - msg_direction: MsgDirection::In, - msg_name: "data_has_required".to_string(), - }]; - - assert_eq!(compatibles.data, expected_compatibles); - - println!("Response body: {:?}", compatibles); - } - #[actix_web::test] async fn test_get_compatible_messages_cmd_no_property() { let mut dev_server_state = DevServerState { diff --git a/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_1_manifest.json b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_1_manifest.json index 3cf6a6ace6..410462b6ac 100644 --- a/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_1_manifest.json +++ b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_1_manifest.json @@ -1,88 +1,112 @@ { - "type": "extension", - "name": "extension_addon_1", - "version": "0.1.0", - "dependencies": [ + "type": "extension", + "name": "extension_addon_1", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.1.0" + } + ], + "api": { + "cmd_out": [ { - "type": "system", - "name": "ten_runtime", - "version": "0.1.0" - } - ], - "api": { - "cmd_out": [ - { - "name": "cmd1" - }, - { - "name": "cmd2", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } + "name": "test_cmd", + "property": { + "test_property": { + "type": "int8" + } + } + }, + { + "name": "has_required", + "property": { + "foo": { + "type": "string" } }, - { - "name": "cmd3", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } + "required": ["foo"] + }, + { + "name": "has_required_mismatch", + "property": { + "foo": { + "type": "string" } }, - { - "name": "cmd4", - "result": { - "property": { - "a": { - "type": "string" - } - } + "required": ["foo"] + }, + { + "name": "cmd1" + }, + { + "name": "cmd2", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" } } - ], - "data_out": [ - { - "name": "data1", - "property": { - "a": { - "type": "string" - } + }, + { + "name": "cmd3", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" } - }, - { - "name": "data2", + } + }, + { + "name": "cmd4", + "result": { "property": { "a": { "type": "string" - }, - "b": { - "type": "object", - "properties": { - "c": { - "type": "int8" - }, - "d": { - "type": "bool" - } - }, - "required": [ - "c" - ] } } } - ], - "video_frame_out": [ - { - "name": "pcm_frame1" + } + ], + "data_out": [ + { + "name": "data1", + "property": { + "a": { + "type": "string" + } } - ] - } - } \ No newline at end of file + }, + { + "name": "data2", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "object", + "properties": { + "c": { + "type": "int8" + }, + "d": { + "type": "bool" + } + }, + "required": ["c"] + } + } + } + ], + "video_frame_out": [ + { + "name": "pcm_frame1" + } + ] + } +} diff --git a/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_2_manifest.json b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_2_manifest.json index c063c0d505..cfaaeda634 100644 --- a/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_2_manifest.json +++ b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_2_manifest.json @@ -1,85 +1,113 @@ { - "type": "extension", - "name": "extension_addon_2", - "version": "0.1.0", - "dependencies": [ + "type": "extension", + "name": "extension_addon_2", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.1.0" + } + ], + "api": { + "cmd_in": [ { - "type": "system", - "name": "ten_runtime", - "version": "0.1.0" - } - ], - "api": { - "cmd_in": [ - { - "name": "cmd1" - }, - { - "name": "cmd2", - "property": { - "a": { - "type": "string" - }, - "c": { - "type": "bool" - } + "name": "test_cmd", + "property": { + "test_property": { + "type": "int32" + } + } + }, + { + "name": "another_test_cmd", + "property": { + "test_property": { + "type": "int8" + } + } + }, + { + "name": "has_required", + "property": { + "foo": { + "type": "string" } }, - { - "name": "cmd3", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } + "required": ["foo"] + }, + { + "name": "has_required_mismatch", + "property": { + "foo": { + "type": "string" + } + } + }, + { + "name": "cmd1" + }, + { + "name": "cmd2", + "property": { + "a": { + "type": "string" }, - "required": [ - "a" - ] - }, - { - "name": "cmd4" + "c": { + "type": "bool" + } } - ], - "data_in": [ - { - "name": "data1" + }, + { + "name": "cmd3", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" + } }, - { - "name": "data2", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "object", - "properties": { - "c": { - "type": "int8" - }, - "d": { - "type": "bool" - } + "required": ["a"] + }, + { + "name": "cmd4" + } + ], + "data_in": [ + { + "name": "data1" + }, + { + "name": "data2", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "object", + "properties": { + "c": { + "type": "int8" }, - "required": [ - "c", - "d" - ] - } + "d": { + "type": "bool" + } + }, + "required": ["c", "d"] } } - ], - "video_frame_in": [ - { - "name": "pcm_frame1", - "property": { - "a": { - "type": "string" - } + } + ], + "video_frame_in": [ + { + "name": "pcm_frame1", + "property": { + "a": { + "type": "string" } } - ] - } - } \ No newline at end of file + } + ] + } +} diff --git a/core/src/ten_manager/src/dev_server/property/check.rs b/core/src/ten_manager/src/dev_server/property/check.rs index 5587b6e047..fb28acfece 100644 --- a/core/src/ten_manager/src/dev_server/property/check.rs +++ b/core/src/ten_manager/src/dev_server/property/check.rs @@ -105,10 +105,8 @@ mod tests { // The first item is 'manifest.json', and the second item is // 'property.json'. let all_pkgs_json = vec![( - include_str!("test_data_embed/all_data_type_app_manifest.json") - .to_string(), - include_str!("test_data_embed/all_data_type_app_property.json") - .to_string(), + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), )]; let inject_ret = diff --git a/core/src/ten_manager/src/dev_server/property/dump.rs b/core/src/ten_manager/src/dev_server/property/dump.rs index 1e618e067c..4190de4b0d 100644 --- a/core/src/ten_manager/src/dev_server/property/dump.rs +++ b/core/src/ten_manager/src/dev_server/property/dump.rs @@ -132,39 +132,10 @@ mod tests { tman_config: TmanConfig::default(), }; - let all_pkgs_json = vec![ - ( - include_str!( - "../test_data_embed/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data_embed/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_1_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_2_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ( - include_str!( - "../test_data_embed/extension_addon_3_manifest.json" - ) - .to_string(), - "{}".to_string(), - ), - ]; + let all_pkgs_json = vec![( + include_str!("test_data_embed/app_manifest.json").to_string(), + include_str!("test_data_embed/app_property.json").to_string(), + )]; let inject_ret = inject_all_pkgs_for_mock(&mut dev_server_state, all_pkgs_json); @@ -187,7 +158,7 @@ mod tests { .await; let input_data: Value = serde_json::from_str(include_str!( - "test_data_embed/test_dump_property_success_input_data.json" + "test_data_embed/dump_property_success_input_data.json" )) .unwrap(); diff --git a/core/src/ten_manager/src/dev_server/property/test_data_embed/all_data_type_app_manifest.json b/core/src/ten_manager/src/dev_server/property/test_data_embed/app_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/property/test_data_embed/all_data_type_app_manifest.json rename to core/src/ten_manager/src/dev_server/property/test_data_embed/app_manifest.json diff --git a/core/src/ten_manager/src/dev_server/property/test_data_embed/all_data_type_app_property.json b/core/src/ten_manager/src/dev_server/property/test_data_embed/app_property.json similarity index 100% rename from core/src/ten_manager/src/dev_server/property/test_data_embed/all_data_type_app_property.json rename to core/src/ten_manager/src/dev_server/property/test_data_embed/app_property.json diff --git a/core/src/ten_manager/src/dev_server/property/test_data_embed/test_dump_property_success_input_data.json b/core/src/ten_manager/src/dev_server/property/test_data_embed/dump_property_success_input_data.json similarity index 100% rename from core/src/ten_manager/src/dev_server/property/test_data_embed/test_dump_property_success_input_data.json rename to core/src/ten_manager/src/dev_server/property/test_data_embed/dump_property_success_input_data.json