diff --git a/.github/workflows/build_mac.yml b/.github/workflows/build_mac.yml index 0dbe5b6bd..7ddb510e8 100644 --- a/.github/workflows/build_mac.yml +++ b/.github/workflows/build_mac.yml @@ -39,18 +39,32 @@ jobs: - name: Install tools and dependencies run: | + + if [ ${{ matrix.build_type }} == "debug" ]; then + # Since the TEN runtime and TEN manager are a combination of C and + # Rust, to enable ASan, the ASan versions used by both the C and + # Rust compilation environments must be consistent. Therefore, it is + # necessary to lock the LLVM and Rust versions to enable ASan. + brew install llvm@18 + rustup default nightly-2024-07-19 + else + rustup default nightly + fi + brew install tree pip3 install --use-pep517 python-dotenv jinja2 go install golang.org/dl/go1.20.12@latest && go1.20.12 download go env -w GOFLAGS="-buildvcs=false" - rustup default nightly cargo install --force cbindgen - name: Build run: | + if [ ${{ matrix.build_type }} == "debug" ]; then + export PATH="/opt/homebrew/opt/llvm@18/bin:$PATH" + fi export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_test=false ten_enable_go_binding=${{ matrix.build_type == 'debug' && 'false' || 'true' }} ten_enable_package_manager=${{ matrix.build_type == 'debug' && 'false' || 'true' }} enable_sanitizer=false + tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_test=false tgn build mac arm64 ${{ matrix.build_type }} tree -I 'gen|obj' out @@ -58,7 +72,7 @@ jobs: runs-on: macos-13 strategy: matrix: - build_type: [debug, release] + build_type: [release] steps: - uses: actions/checkout@v4 with: @@ -76,17 +90,31 @@ jobs: - name: Install tools and dependencies run: | + + if [ ${{ matrix.build_type }} == "debug" ]; then + # Since the TEN runtime and TEN manager are a combination of C and + # Rust, to enable ASan, the ASan versions used by both the C and + # Rust compilation environments must be consistent. Therefore, it is + # necessary to lock the LLVM and Rust versions to enable ASan. + brew install llvm@18 + rustup default nightly-2024-07-19 + else + rustup default nightly + fi + brew install tree pip3 install --use-pep517 python-dotenv jinja2 go install golang.org/dl/go1.20.12@latest && go1.20.12 download go env -w GOFLAGS="-buildvcs=false" - rustup default nightly cargo install --force cbindgen - name: Build run: | + if [ ${{ matrix.build_type }} == "debug" ]; then + export PATH="/usr/local/opt/llvm@18/bin:$PATH" + fi export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_test=false ten_enable_go_binding=${{ matrix.build_type == 'debug' && 'false' || 'true' }} ten_enable_package_manager=${{ matrix.build_type == 'debug' && 'false' || 'true' }} enable_sanitizer=false + tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_test=false tgn build mac x64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/build/common/rust/rust.gni b/build/common/rust/rust.gni index 3cb41b481..bcf12d30c 100644 --- a/build/common/rust/rust.gni +++ b/build/common/rust/rust.gni @@ -171,6 +171,14 @@ template("rust_test") { rebase_path(tg_timestamp_proxy_file), ] + if (defined(invoker.integration_test_output_name) && + invoker.integration_test_output_name != "") { + args += [ + "--integration-test-output-name", + invoker.integration_test_output_name, + ] + } + args += [ "--build-type" ] if (is_debug) { args += [ "debug" ] @@ -256,13 +264,6 @@ template("rust_test") { target, ] - if (defined(invoker.through_real_test) && invoker.through_real_test) { - args += [ - "--through-real-test", - "True", - ] - } - forward_variables_from(invoker, [ "deps", diff --git a/build/common/rust/rust_build_tests.py b/build/common/rust/rust_build_tests.py index 949084e98..a6949c00f 100644 --- a/build/common/rust/rust_build_tests.py +++ b/build/common/rust/rust_build_tests.py @@ -5,16 +5,16 @@ # Refer to the "LICENSE" file in the root directory for more information. # import argparse +import json import sys import os -import platform from build.scripts import cmd_exec, fs_utils, timestamp_proxy class ArgumentInfo(argparse.Namespace): def __init__(self): super().__init__() - self.through_real_test: bool + self.no_run: bool self.project_path: str self.build_type: str self.target_path: str @@ -22,59 +22,71 @@ def __init__(self): self.log_level: int self.test_output_dir: str self.tg_timestamp_proxy_file: str | None = None + self.integration_test_output_name: str | None = None + + +def get_crate_test_output_name(log_level: int) -> str: + cmd = ["cargo", "metadata", "--no-deps", "--format-version", "1"] + returncode, output = cmd_exec.run_cmd(cmd, log_level) + if returncode: + raise Exception(f"Failed to get crate name: {output}") + + # Get the last line of the output, as there might be some note or warning + # messages from cargo. + output = output.splitlines()[-1] + metadata = json.loads(output) + for target in metadata["packages"][0]["targets"]: + if target["test"]: + return target["name"] + + raise Exception("Failed to get crate name from targets.") def copy_test_binaries( - through_real_test: bool, source_dir: str, + base_name: str, output_dir: str, + target_name: str, log_level: int = 0, ): if log_level > 0: - print(f"Copying test binaries from {source_dir} to {output_dir}") + print( + f"Copying test binary {base_name} from {source_dir} to {output_dir}" + ) - if through_real_test: - if platform.system() == "Windows": - executable_name = "tman_test.exe" - else: - executable_name = "tman_test" + for f in os.listdir(source_dir): + is_executable = os.access(os.path.join(source_dir, f), os.X_OK) + if not is_executable: + continue + + # The file name generated by `cargo build` always has a hash suffix, ex: + # -.. We need to remove the hash suffix. + + # We have to deal with the extension of the executable file, as if the + # `crate-type` is `cdylib`, the extension is `.so` on linux, which is + # not what we want. The extension is not present on linux or macos, and + # the extension is '.exe' on windows. + extension = os.path.splitext(f)[1] + if extension != "" and extension != ".exe": + continue + + binary_name = f[: f.rindex("-") if "-" in f else -1] + if binary_name != base_name: + continue + + dest = target_name + extension fs_utils.copy_file( - os.path.join(source_dir, executable_name), - os.path.join(output_dir, executable_name), + os.path.join(source_dir, f), + os.path.join(output_dir, dest), True, ) - else: - for f in os.listdir(source_dir): - is_executable = os.access(os.path.join(source_dir, f), os.X_OK) - if not is_executable: - continue - - # The file name generated by `cargo build` always has a hash suffix, - # ex: -.. We need to remove the hash - # suffix. - - # We have to deal with the extension of the executable file, as if - # the `crate-type` is `cdylib`, the extension is `.so` on linux, - # which is not what we want. The extension is not present on linux - # or macos, and the extension is '.exe' on windows. - extension = os.path.splitext(f)[1] - if extension != "" and extension != ".exe": - continue - - ff = f[: f.rindex("-") if "-" in f else -1] + extension - - fs_utils.copy_file( - os.path.join(source_dir, f), - os.path.join(output_dir, ff), - True, - ) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--through-real-test", type=bool, default=False) + parser.add_argument("--no-run", type=bool, default=True) parser.add_argument("--project-path", type=str, required=True) parser.add_argument("--manifest-path", type=str, required=False) parser.add_argument("--build-type", type=str, required=True) @@ -88,6 +100,9 @@ def copy_test_binaries( parser.add_argument( "--tg-timestamp-proxy-file", type=str, default="", required=False ) + parser.add_argument( + "--integration-test-output-name", type=str, required=False + ) arg_info = ArgumentInfo() args = parser.parse_args(namespace=arg_info) @@ -108,24 +123,30 @@ def copy_test_binaries( try: os.chdir(args.project_path) - if args.through_real_test: + # cargo build --tests: only compile the test source files, without + # running the test cases. + # cargo test: compile the test source files and run the test cases. + # + # `cargo build --tests` or `cargo test --no-run` will not trigger the + # `runner` script in .cargo/config.toml. + if args.no_run: cmd = [ "cargo", - "test", + "build", "--target-dir", args.target_path, "--target", args.target, + "--tests", ] else: cmd = [ "cargo", - "build", + "test", "--target-dir", args.target_path, "--target", args.target, - "--tests", ] if args.build_type == "release": @@ -134,23 +155,45 @@ def copy_test_binaries( returncode, logs = cmd_exec.run_cmd(cmd, args.log_level) if returncode: raise Exception(f"Failed to build rust tests: {logs}") + else: + print(logs) - # The output of the dependencies will be in / - # /deps, while the output of the tests will be in / - # //deps. + # The prefix of the unit test binary is the crate name (i.e., the + # 'name' in [[bin]] or [[lib]] in a crate). + unit_test_output_name = get_crate_test_output_name(args.log_level) + + # The output of the tests will be in + # ///deps if args.test_output_dir != "": + # Copy the unit test binary. copy_test_binaries( - args.through_real_test, os.path.join( args.target_path, args.target, args.build_type, "deps", ), + unit_test_output_name, args.test_output_dir, + "unit_test", args.log_level, ) + if args.integration_test_output_name: + # Copy the integration test binary. + copy_test_binaries( + os.path.join( + args.target_path, + args.target, + args.build_type, + "deps", + ), + args.integration_test_output_name, + args.test_output_dir, + "integration_test", + args.log_level, + ) + # Success to build the app, update the stamp file to represent this # fact. timestamp_proxy.touch_timestamp_proxy_file(args.tg_timestamp_proxy_file) diff --git a/core/src/ten_manager/.cargo/config.toml b/core/src/ten_manager/.cargo/config.toml deleted file mode 100644 index d999e92fd..000000000 --- a/core/src/ten_manager/.cargo/config.toml +++ /dev/null @@ -1,32 +0,0 @@ -# Windows targets -[target.i686-pc-windows-msvc] -runner = "python ./tools/test_runner.py" - -[target.x86_64-pc-windows-msvc] -runner = "python ./tools/test_runner.py" - -[target.aarch64-pc-windows-msvc] -runner = "python ./tools/test_runner.py" - -# Linux targets -[target.aarch64-unknown-linux-gnu] -runner = "python3 ./tools/test_runner.py" - -[target.armv7-unknown-linux-gnueabi] -runner = "python3 ./tools/test_runner.py" - -[target.i686-unknown-linux-gnu] -runner = "python3 ./tools/test_runner.py" - -[target.x86_64-unknown-linux-gnu] -runner = "python3 ./tools/test_runner.py" - -# macOS targets -[target.aarch64-apple-darwin] -runner = "python3 ./tools/test_runner.py" - -[target.i686-apple-darwin] -runner = "python3 ./tools/test_runner.py" - -[target.x86_64-apple-darwin] -runner = "python3 ./tools/test_runner.py" diff --git a/core/src/ten_manager/BUILD.gn b/core/src/ten_manager/BUILD.gn index da317d6d9..f06ef4ef7 100644 --- a/core/src/ten_manager/BUILD.gn +++ b/core/src/ten_manager/BUILD.gn @@ -25,8 +25,7 @@ if (ten_enable_package_manager) { utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils") env += [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ] - test_output_dir = "${root_out_dir}/tests/standalone" - through_real_test = true + test_output_dir = "${root_out_dir}/tests/standalone/ten_manager" deps = [ "//core/src/ten_rust:ten_rust_static_lib", 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 629af2faf..ab2df62e3 100644 --- a/core/src/ten_manager/src/dev_server/addons/extensions.rs +++ b/core/src/ten_manager/src/dev_server/addons/extensions.rs @@ -173,27 +173,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + 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 000000000..06ce9b2a9 --- /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/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/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/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/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/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/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/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/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 8450f6289..81f69761d 100644 --- a/core/src/ten_manager/src/dev_server/graphs/connections.rs +++ b/core/src/ten_manager/src/dev_server/graphs/connections.rs @@ -193,27 +193,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_3_manifest.json") .to_string(), "{}".to_string(), ), @@ -283,18 +277,18 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("test_data/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/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/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/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 eec5f750b..704811c20 100644 --- a/core/src/ten_manager/src/dev_server/graphs/mod.rs +++ b/core/src/ten_manager/src/dev_server/graphs/mod.rs @@ -99,27 +99,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + 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 e07c5051c..5f5b2935f 100644 --- a/core/src/ten_manager/src/dev_server/graphs/nodes.rs +++ b/core/src/ten_manager/src/dev_server/graphs/nodes.rs @@ -376,27 +376,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_3_manifest.json") .to_string(), "{}".to_string(), ), @@ -647,27 +641,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + 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/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/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 000000000..ebe4b76dc --- /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 new file mode 100644 index 000000000..fa4ce727d --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_1_manifest.json @@ -0,0 +1,46 @@ +{ + "type": "extension", + "name": "extension_addon_1", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "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 new file mode 100644 index 000000000..bd46c6379 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/graphs/test_data_embed/extension_addon_2_manifest.json @@ -0,0 +1,64 @@ +{ + "type": "extension", + "name": "extension_addon_2", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "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 000000000..aee78b320 --- /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/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/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/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/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/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 similarity index 100% rename from core/src/ten_manager/src/dev_server/graphs/test_data/extension_addon_1_manifest.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_1_manifest.json diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data/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 similarity index 100% rename from core/src/ten_manager/src/dev_server/graphs/test_data/extension_addon_2_manifest.json rename to core/src/ten_manager/src/dev_server/graphs/test_data_embed/get_connections_have_all_data_type/extension_addon_2_manifest.json diff --git a/core/src/ten_manager/src/dev_server/graphs/test_data/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/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 8e397cb05..02fdea7cd 100644 --- a/core/src/ten_manager/src/dev_server/graphs/update.rs +++ b/core/src/ten_manager/src/dev_server/graphs/update.rs @@ -197,27 +197,21 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_3_manifest.json") .to_string(), "{}".to_string(), ), @@ -240,7 +234,7 @@ mod tests { .await; let input_data: Value = serde_json::from_str(include_str!( - "test_data/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 c57430425..859ebbb64 100644 --- a/core/src/ten_manager/src/dev_server/messages/compatible.rs +++ b/core/src/ten_manager/src/dev_server/messages/compatible.rs @@ -326,27 +326,16 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), @@ -417,27 +406,16 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!("../test_data/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/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), @@ -490,27 +468,16 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/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/extension_addon_1_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_2_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), @@ -581,27 +548,16 @@ mod tests { let all_pkgs_json = vec![ ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!("../test_data/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/extension_addon_2_manifest.json") + include_str!("test_data_embed/extension_addon_1_manifest.json") .to_string(), "{}".to_string(), ), ( - include_str!("../test_data/extension_addon_3_manifest.json") + include_str!("test_data_embed/extension_addon_2_manifest.json") .to_string(), "{}".to_string(), ), @@ -661,97 +617,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/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!("../test_data/extension_addon_1_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/extension_addon_2_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/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 { @@ -764,23 +629,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -862,23 +721,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -950,23 +803,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -1027,23 +874,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -1114,23 +955,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -1203,23 +1038,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; @@ -1280,23 +1109,17 @@ mod tests { // 'property.json'. let all_pkgs_json = vec![ ( - include_str!("../test_data/compatible/app_manifest.json") - .to_string(), - include_str!("../test_data/compatible/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/compatible/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/compatible/extension_addon_2_manifest.json" - ) - .to_string(), + include_str!("test_data_embed/extension_addon_2_manifest.json") + .to_string(), "{}".to_string(), ), ]; diff --git a/core/src/ten_manager/src/dev_server/test_data/compatible/app_manifest.json b/core/src/ten_manager/src/dev_server/messages/test_data_embed/app_manifest.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data/compatible/app_manifest.json rename to core/src/ten_manager/src/dev_server/messages/test_data_embed/app_manifest.json diff --git a/core/src/ten_manager/src/dev_server/test_data/compatible/app_property.json b/core/src/ten_manager/src/dev_server/messages/test_data_embed/app_property.json similarity index 100% rename from core/src/ten_manager/src/dev_server/test_data/compatible/app_property.json rename to core/src/ten_manager/src/dev_server/messages/test_data_embed/app_property.json 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 new file mode 100644 index 000000000..410462b6a --- /dev/null +++ b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_1_manifest.json @@ -0,0 +1,112 @@ +{ + "type": "extension", + "name": "extension_addon_1", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.1.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"] + }, + { + "name": "cmd1" + }, + { + "name": "cmd2", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" + } + } + }, + { + "name": "cmd3", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" + } + } + }, + { + "name": "cmd4", + "result": { + "property": { + "a": { + "type": "string" + } + } + } + } + ], + "data_out": [ + { + "name": "data1", + "property": { + "a": { + "type": "string" + } + } + }, + { + "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 new file mode 100644 index 000000000..cfaaeda63 --- /dev/null +++ b/core/src/ten_manager/src/dev_server/messages/test_data_embed/extension_addon_2_manifest.json @@ -0,0 +1,113 @@ +{ + "type": "extension", + "name": "extension_addon_2", + "version": "0.1.0", + "dependencies": [ + { + "type": "system", + "name": "ten_runtime", + "version": "0.1.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" + } + } + }, + { + "name": "cmd1" + }, + { + "name": "cmd2", + "property": { + "a": { + "type": "string" + }, + "c": { + "type": "bool" + } + } + }, + { + "name": "cmd3", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "int8" + } + }, + "required": ["a"] + }, + { + "name": "cmd4" + } + ], + "data_in": [ + { + "name": "data1" + }, + { + "name": "data2", + "property": { + "a": { + "type": "string" + }, + "b": { + "type": "object", + "properties": { + "c": { + "type": "int8" + }, + "d": { + "type": "bool" + } + }, + "required": ["c", "d"] + } + } + } + ], + "video_frame_in": [ + { + "name": "pcm_frame1", + "property": { + "a": { + "type": "string" + } + } + } + ] + } +} 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 f03890787..b07da2316 100644 --- a/core/src/ten_manager/src/dev_server/property/check.rs +++ b/core/src/ten_manager/src/dev_server/property/check.rs @@ -106,10 +106,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/all_data_type_app_manifest.json") - .to_string(), - include_str!("test_data/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 2c8515670..beb973ed4 100644 --- a/core/src/ten_manager/src/dev_server/property/dump.rs +++ b/core/src/ten_manager/src/dev_server/property/dump.rs @@ -133,33 +133,10 @@ mod tests { tman_config: TmanConfig::default(), }; - let all_pkgs_json = vec![ - ( - include_str!( - "../test_data/large_response_source_app_manifest.json" - ) - .to_string(), - include_str!( - "../test_data/large_response_source_app_property.json" - ) - .to_string(), - ), - ( - include_str!("../test_data/extension_addon_1_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/extension_addon_2_manifest.json") - .to_string(), - "{}".to_string(), - ), - ( - include_str!("../test_data/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); @@ -182,7 +159,7 @@ mod tests { .await; let input_data: Value = serde_json::from_str(include_str!( - "test_data/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/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/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/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/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/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/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 diff --git a/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_1_manifest.json b/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_1_manifest.json deleted file mode 100644 index 3cf6a6ace..000000000 --- a/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_1_manifest.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "type": "extension", - "name": "extension_addon_1", - "version": "0.1.0", - "dependencies": [ - { - "type": "system", - "name": "ten_runtime", - "version": "0.1.0" - } - ], - "api": { - "cmd_out": [ - { - "name": "cmd1" - }, - { - "name": "cmd2", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } - } - }, - { - "name": "cmd3", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } - } - }, - { - "name": "cmd4", - "result": { - "property": { - "a": { - "type": "string" - } - } - } - } - ], - "data_out": [ - { - "name": "data1", - "property": { - "a": { - "type": "string" - } - } - }, - { - "name": "data2", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "object", - "properties": { - "c": { - "type": "int8" - }, - "d": { - "type": "bool" - } - }, - "required": [ - "c" - ] - } - } - } - ], - "video_frame_out": [ - { - "name": "pcm_frame1" - } - ] - } - } \ No newline at end of file diff --git a/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_2_manifest.json b/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_2_manifest.json deleted file mode 100644 index c063c0d50..000000000 --- a/core/src/ten_manager/src/dev_server/test_data/compatible/extension_addon_2_manifest.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "type": "extension", - "name": "extension_addon_2", - "version": "0.1.0", - "dependencies": [ - { - "type": "system", - "name": "ten_runtime", - "version": "0.1.0" - } - ], - "api": { - "cmd_in": [ - { - "name": "cmd1" - }, - { - "name": "cmd2", - "property": { - "a": { - "type": "string" - }, - "c": { - "type": "bool" - } - } - }, - { - "name": "cmd3", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "int8" - } - }, - "required": [ - "a" - ] - }, - { - "name": "cmd4" - } - ], - "data_in": [ - { - "name": "data1" - }, - { - "name": "data2", - "property": { - "a": { - "type": "string" - }, - "b": { - "type": "object", - "properties": { - "c": { - "type": "int8" - }, - "d": { - "type": "bool" - } - }, - "required": [ - "c", - "d" - ] - } - } - } - ], - "video_frame_in": [ - { - "name": "pcm_frame1", - "property": { - "a": { - "type": "string" - } - } - } - ] - } - } \ No newline at end of file diff --git a/core/src/ten_manager/tools/test_runner.py b/core/src/ten_manager/tools/test_runner.py deleted file mode 100755 index b9fe06d40..000000000 --- a/core/src/ten_manager/tools/test_runner.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import shutil -import sys -from pathlib import Path -import subprocess -import platform - - -def main(executable_path, *args): - print("tman_test executable path:", executable_path) - print("tman_test arguments:", args) - - src_path = Path(executable_path).parent - - if platform.system() == "Windows": - target_filename = "tman_test.exe" - else: - target_filename = "tman_test" - - target_path = os.path.join(src_path, target_filename) - - shutil.copy(executable_path, target_path) - - # Prepare the command with arguments passed to the script. - command = [str(executable_path)] + list(args) - print("tman_test final test command:", command) - - result = subprocess.run(command, capture_output=True, text=True) - - print("STDOUT:", result.stdout) - print("STDERR:", result.stderr) - - exit(result.returncode) - - -if __name__ == "__main__": - main(*sys.argv[1:]) diff --git a/core/src/ten_rust/BUILD.gn b/core/src/ten_rust/BUILD.gn index 8e8299d73..c5698d150 100644 --- a/core/src/ten_rust/BUILD.gn +++ b/core/src/ten_rust/BUILD.gn @@ -8,22 +8,25 @@ import("//build/common/rust/rust.gni") import("//build/ten_rust/options.gni") copy("ten_rust_test_data") { - sources = [ "//core/src/ten_rust/ten_rust_test_data" ] - outputs = [ "${root_out_dir}/tests/standalone/ten_rust_test_data" ] + sources = [ "//core/src/ten_rust/tests/test_data" ] + outputs = [ "${root_out_dir}/tests/standalone/ten_rust/tests/test_data" ] } if (enable_ten_rust) { - rust_test("ten_rust_test") { - project_path = "//core/src/ten_rust" - test_output_dir = "${root_out_dir}/tests/standalone" + if (is_linux || is_win || (is_mac && target_cpu == "x64")) { + rust_test("ten_rust_test") { + project_path = "//core/src/ten_rust" + test_output_dir = "${root_out_dir}/tests/standalone/ten_rust" + integration_test_output_name = "integration_test" - utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils") - env = [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ] + utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils") + env = [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ] - deps = [ - ":ten_rust_build_deps", - ":ten_rust_test_data", - ] + deps = [ + ":ten_rust_build_deps", + ":ten_rust_test_data", + ] + } } } @@ -74,6 +77,9 @@ group("ten_rust") { if (enable_ten_rust) { public_deps += [ ":ten_rust_binding" ] - deps += [ ":ten_rust_test" ] + + if (is_linux || is_win || (is_mac && target_cpu == "x64")) { + deps += [ ":ten_rust_test" ] + } } } diff --git a/core/src/ten_rust/src/interface/mod.rs b/core/src/ten_rust/src/interface/mod.rs index ceeedf37d..8062e8b91 100644 --- a/core/src/ten_rust/src/interface/mod.rs +++ b/core/src/ten_rust/src/interface/mod.rs @@ -121,66 +121,3 @@ pub fn ten_interface_schema_resolve_definition( Ok(content_json) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_interface_ref_local() { - let content = r#" - [ - { - "name": "ia", - "cmd": [ - { - "name": "foo" - } - ] - }, - { - "name": "ib", - "$ref": "file://ten_rust_test_data/foo.json" - } - ] - "#; - - let result = ten_interface_schema_resolve_definition(content, "."); - assert!(result.is_ok()); - - let content_json = result.unwrap(); - assert_eq!(content_json.as_array().unwrap().len(), 2); - - let ib = content_json - .as_array() - .unwrap() - .get(1) - .unwrap() - .as_object() - .unwrap(); - assert!(ib.contains_key("cmd")) - } - - #[test] - fn test_interface_name_duplicated() { - let content = r#" - [ - { - "name": "ia", - "cmd": [ - { - "name": "foo" - } - ] - }, - { - "name": "ia", - "$ref": "file://foo.json" - } - ] - "#; - - let result = ten_interface_schema_resolve_definition(content, "."); - assert!(result.is_err()); - } -} diff --git a/core/src/ten_rust/src/lib.rs b/core/src/ten_rust/src/lib.rs index 9d5d1c207..b6c0528c2 100644 --- a/core/src/ten_rust/src/lib.rs +++ b/core/src/ten_rust/src/lib.rs @@ -5,7 +5,7 @@ // Refer to the "LICENSE" file in the root directory for more information. // mod bindings; -mod interface; +pub mod interface; pub mod json; pub mod json_schema; pub mod pkg_info; diff --git a/core/src/ten_rust/src/pkg_info/graph/mod.rs b/core/src/ten_rust/src/pkg_info/graph/mod.rs index 5f7c51cf1..24b861aaf 100644 --- a/core/src/ten_rust/src/pkg_info/graph/mod.rs +++ b/core/src/ten_rust/src/pkg_info/graph/mod.rs @@ -211,20 +211,16 @@ impl From for GraphDestination { #[cfg(test)] mod tests { - use std::{path::Path, str::FromStr}; + use std::str::FromStr; - use crate::pkg_info::{ - get_all_existed_pkgs_info_of_app, - pkg_type::PkgType, - property::{predefined_graph::PropertyPredefinedGraph, Property}, - }; + use crate::pkg_info::property::Property; use super::*; #[test] fn test_predefined_graph_has_no_extensions() { let property_str = - include_str!("test_data/predefined_graph_no_extensions.json"); + include_str!("test_data_embed/predefined_graph_no_extensions.json"); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -240,7 +236,7 @@ mod tests { #[test] fn test_predefined_graph_has_extension_duplicated() { let property_str = include_str!( - "test_data/predefined_graph_has_duplicated_extension.json" + "test_data_embed/predefined_graph_has_duplicated_extension.json" ); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -257,7 +253,7 @@ mod tests { #[test] fn test_start_graph_cmd_has_extension_duplicated() { let cmd_str = include_str!( - "test_data/start_graph_cmd_has_duplicated_extension.json" + "test_data_embed/start_graph_cmd_has_duplicated_extension.json" ); let mut graph: Graph = Graph::from_str(cmd_str).unwrap(); @@ -271,7 +267,7 @@ mod tests { #[test] fn test_predefined_graph_has_ext_group_duplicated() { let property_str = include_str!( - "test_data/predefined_graph_has_duplicated_ext_group.json" + "test_data_embed/predefined_graph_has_duplicated_ext_group.json" ); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -288,8 +284,9 @@ mod tests { #[test] fn test_predefined_graph_has_unused_extension_group() { - let property_str = - include_str!("test_data/predefined_graph_unused_ext_group.json"); + let property_str = include_str!( + "test_data_embed/predefined_graph_unused_ext_group.json" + ); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -306,7 +303,7 @@ mod tests { #[test] fn test_predefined_graph_connection_src_not_found() { let property_str = include_str!( - "test_data/predefined_graph_connection_src_not_found.json" + "test_data_embed/predefined_graph_connection_src_not_found.json" ); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -325,7 +322,7 @@ mod tests { #[test] fn test_predefined_graph_connection_dest_not_found() { let property_str = include_str!( - "test_data/predefined_graph_connection_dest_not_found.json" + "test_data_embed/predefined_graph_connection_dest_not_found.json" ); let mut property: Property = Property::from_str(property_str).unwrap(); assert!(property.validate_and_complete().is_ok()); @@ -340,103 +337,4 @@ mod tests { assert!(result.is_err()); println!("Error: {:?}", result.err().unwrap()); } - - #[test] - fn test_predefined_graph_nodes_have_installed() { - let app_dir = "ten_rust_test_data/check_predefined_graph_success"; - let pkg_infos = - get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); - assert!(!pkg_infos.is_empty()); - - let app_pkg_info = pkg_infos - .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) - .last(); - let app_pkg = app_pkg_info.unwrap(); - let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); - let predefined_graph: PropertyPredefinedGraph = - pkg_graph.clone().into(); - let graph = &predefined_graph.graph; - - let mut pkg_info_map: HashMap> = HashMap::new(); - pkg_info_map.insert(default_app_loc(), pkg_infos); - - let result = graph.check_if_nodes_have_installed(&pkg_info_map); - assert!(result.is_ok()); - } - - #[test] - fn test_check_graph_extension_not_installed() { - let app_dir = "ten_rust_test_data/check_graph_extension_not_installed"; - let pkg_infos = - get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); - assert!(!pkg_infos.is_empty()); - - let app_pkg_info = pkg_infos - .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) - .last(); - let app_pkg = app_pkg_info.unwrap(); - let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); - let predefined_graph: PropertyPredefinedGraph = - pkg_graph.clone().into(); - let graph = &predefined_graph.graph; - - let mut pkg_info_map: HashMap> = HashMap::new(); - pkg_info_map.insert(default_app_loc(), pkg_infos); - - let result = graph.check_if_nodes_have_installed(&pkg_info_map); - assert!(result.is_err()); - println!("Error: {:?}", result.err().unwrap()); - } - - #[test] - fn test_predefined_graph_check_success() { - let app_dir = "ten_rust_test_data/check_predefined_graph_success"; - let pkg_infos = - get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); - assert!(!pkg_infos.is_empty()); - - let app_pkg_info = pkg_infos - .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) - .last(); - let app_pkg = app_pkg_info.unwrap(); - let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); - let predefined_graph: PropertyPredefinedGraph = - pkg_graph.clone().into(); - let graph = &predefined_graph.graph; - - let mut pkg_info_map: HashMap> = HashMap::new(); - pkg_info_map.insert(default_app_loc(), pkg_infos); - - let result = graph.check(&pkg_info_map); - assert!(result.is_ok()); - } - - #[test] - fn test_check_predefined_graph_all_msgs_incompatible() { - let app_dir = - "ten_rust_test_data/check_predefined_graph_all_types_incompatible"; - let pkg_infos = - get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); - assert!(!pkg_infos.is_empty()); - - let app_pkg_info = pkg_infos - .iter() - .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) - .last(); - let app_pkg = app_pkg_info.unwrap(); - let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); - let predefined_graph: PropertyPredefinedGraph = - pkg_graph.clone().into(); - let graph = &predefined_graph.graph; - - let mut pkg_info_map: HashMap> = HashMap::new(); - pkg_info_map.insert(default_app_loc(), pkg_infos); - - let result = graph.check(&pkg_info_map); - assert!(result.is_err()); - println!("Error: {:?}", result.err().unwrap()); - } } diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_connection_dest_not_found.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_connection_dest_not_found.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_connection_dest_not_found.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_connection_dest_not_found.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_connection_src_not_found.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_connection_src_not_found.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_connection_src_not_found.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_connection_src_not_found.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_current_app_no_extensions.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_current_app_no_extensions.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_current_app_no_extensions.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_current_app_no_extensions.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_has_duplicated_ext_group.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_has_duplicated_ext_group.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_has_duplicated_ext_group.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_has_duplicated_ext_group.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_has_duplicated_extension.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_has_duplicated_extension.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_has_duplicated_extension.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_has_duplicated_extension.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_no_extensions.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_no_extensions.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_no_extensions.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_no_extensions.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_unused_ext_group.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_unused_ext_group.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/predefined_graph_unused_ext_group.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/predefined_graph_unused_ext_group.json diff --git a/core/src/ten_rust/src/pkg_info/graph/test_data/start_graph_cmd_has_duplicated_extension.json b/core/src/ten_rust/src/pkg_info/graph/test_data_embed/start_graph_cmd_has_duplicated_extension.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/graph/test_data/start_graph_cmd_has_duplicated_extension.json rename to core/src/ten_rust/src/pkg_info/graph/test_data_embed/start_graph_cmd_has_duplicated_extension.json diff --git a/core/src/ten_rust/src/pkg_info/manifest/mod.rs b/core/src/ten_rust/src/pkg_info/manifest/mod.rs index b35f71297..7bcb939b6 100644 --- a/core/src/ten_rust/src/pkg_info/manifest/mod.rs +++ b/core/src/ten_rust/src/pkg_info/manifest/mod.rs @@ -142,8 +142,9 @@ mod tests { #[test] fn test_extension_manifest_from_str() { - let manifest_str = - include_str!("test_data/test_extension_manifest_from_str.json"); + let manifest_str = include_str!( + "test_data_embed/test_extension_manifest_from_str.json" + ); let result: Result = manifest_str.parse(); assert!(result.is_ok()); diff --git a/core/src/ten_rust/src/pkg_info/manifest/test_data/test_extension_manifest_from_str.json b/core/src/ten_rust/src/pkg_info/manifest/test_data_embed/test_extension_manifest_from_str.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/manifest/test_data/test_extension_manifest_from_str.json rename to core/src/ten_rust/src/pkg_info/manifest/test_data_embed/test_extension_manifest_from_str.json diff --git a/core/src/ten_rust/src/pkg_info/property/predefined_graph.rs b/core/src/ten_rust/src/pkg_info/property/predefined_graph.rs index 8a658cc42..c1bcc8290 100644 --- a/core/src/ten_rust/src/pkg_info/property/predefined_graph.rs +++ b/core/src/ten_rust/src/pkg_info/property/predefined_graph.rs @@ -34,7 +34,7 @@ mod tests { #[test] fn test_property_predefined_graph_deserialize() { - let property_str = include_str!("test_data/property.json"); + let property_str = include_str!("test_data_embed/property.json"); let property = Property::from_str(property_str).unwrap(); assert!(property._ten.is_some()); diff --git a/core/src/ten_rust/src/pkg_info/property/test_data/property.json b/core/src/ten_rust/src/pkg_info/property/test_data_embed/property.json similarity index 100% rename from core/src/ten_rust/src/pkg_info/property/test_data/property.json rename to core/src/ten_rust/src/pkg_info/property/test_data_embed/property.json diff --git a/core/src/ten_rust/src/schema/mod.rs b/core/src/ten_rust/src/schema/mod.rs index 3df159875..eeee11ffe 100644 --- a/core/src/ten_rust/src/schema/mod.rs +++ b/core/src/ten_rust/src/schema/mod.rs @@ -175,7 +175,7 @@ mod tests { #[test] fn test_create_schema_invalid_json() { - let schema_str = include_str!("test_data/invalid_schema.json"); + let schema_str = include_str!("test_data_embed/invalid_schema.json"); let schema_result = create_schema_from_json_string(schema_str); println!("{:?}", schema_result); assert!(schema_result.is_err()); diff --git a/core/src/ten_rust/src/schema/store.rs b/core/src/ten_rust/src/schema/store.rs index df56e3203..0a86a1dfc 100644 --- a/core/src/ten_rust/src/schema/store.rs +++ b/core/src/ten_rust/src/schema/store.rs @@ -315,7 +315,7 @@ mod tests { #[test] fn test_create_schema_store_success() { let manifest_str = include_str!( - "test_data/extension_manifest_has_all_types_schema.json" + "test_data_embed/extension_manifest_has_all_types_schema.json" ); let manifest_result = Manifest::from_str(manifest_str); diff --git a/core/src/ten_rust/src/schema/test_data/extension_manifest_has_all_types_schema.json b/core/src/ten_rust/src/schema/test_data_embed/extension_manifest_has_all_types_schema.json similarity index 100% rename from core/src/ten_rust/src/schema/test_data/extension_manifest_has_all_types_schema.json rename to core/src/ten_rust/src/schema/test_data_embed/extension_manifest_has_all_types_schema.json diff --git a/core/src/ten_rust/src/schema/test_data/invalid_schema.json b/core/src/ten_rust/src/schema/test_data_embed/invalid_schema.json similarity index 100% rename from core/src/ten_rust/src/schema/test_data/invalid_schema.json rename to core/src/ten_rust/src/schema/test_data_embed/invalid_schema.json diff --git a/core/src/ten_rust/tests/graph_check.rs b/core/src/ten_rust/tests/graph_check.rs new file mode 100644 index 000000000..67eb64dbb --- /dev/null +++ b/core/src/ten_rust/tests/graph_check.rs @@ -0,0 +1,82 @@ +// +// This file is part of the TEN Framework project. +// See https://github.com/TEN-framework/ten_framework/LICENSE for license +// information. +// +use std::{collections::HashMap, path::Path}; + +use ten_rust::pkg_info::{ + default_app_loc, get_all_existed_pkgs_info_of_app, pkg_type::PkgType, + property::predefined_graph::PropertyPredefinedGraph, PkgInfo, +}; + +#[test] +fn test_graph_check_extension_not_installed() { + let app_dir = "tests/test_data/graph_check_extension_not_installed"; + let pkg_infos = + get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); + assert!(!pkg_infos.is_empty()); + + let app_pkg_info = pkg_infos + .iter() + .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .last(); + let app_pkg = app_pkg_info.unwrap(); + let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); + let predefined_graph: PropertyPredefinedGraph = pkg_graph.clone().into(); + let graph = &predefined_graph.graph; + + let mut pkg_info_map: HashMap> = HashMap::new(); + pkg_info_map.insert(default_app_loc(), pkg_infos); + + let result = graph.check_if_nodes_have_installed(&pkg_info_map); + assert!(result.is_err()); + println!("Error: {:?}", result.err().unwrap()); +} + +#[test] +fn test_graph_check_predefined_graph_success() { + let app_dir = "tests/test_data/graph_check_predefined_graph_success"; + let pkg_infos = + get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); + assert!(!pkg_infos.is_empty()); + + let app_pkg_info = pkg_infos + .iter() + .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .last(); + let app_pkg = app_pkg_info.unwrap(); + let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); + let predefined_graph: PropertyPredefinedGraph = pkg_graph.clone().into(); + let graph = &predefined_graph.graph; + + let mut pkg_info_map: HashMap> = HashMap::new(); + pkg_info_map.insert(default_app_loc(), pkg_infos); + + let result = graph.check(&pkg_info_map); + assert!(result.is_ok()); +} + +#[test] +fn test_graph_check_all_msgs_schema_incompatible() { + let app_dir = "tests/test_data/graph_check_all_msgs_schema_incompatible"; + let pkg_infos = + get_all_existed_pkgs_info_of_app(Path::new(app_dir)).unwrap(); + assert!(!pkg_infos.is_empty()); + + let app_pkg_info = pkg_infos + .iter() + .filter(|pkg| pkg.pkg_identity.pkg_type == PkgType::App) + .last(); + let app_pkg = app_pkg_info.unwrap(); + let pkg_graph = app_pkg.predefined_graphs.first().unwrap(); + let predefined_graph: PropertyPredefinedGraph = pkg_graph.clone().into(); + let graph = &predefined_graph.graph; + + let mut pkg_info_map: HashMap> = HashMap::new(); + pkg_info_map.insert(default_app_loc(), pkg_infos); + + let result = graph.check(&pkg_info_map); + assert!(result.is_err()); + println!("Error: {:?}", result.err().unwrap()); +} diff --git a/core/src/ten_rust/tests/integration_test.rs b/core/src/ten_rust/tests/integration_test.rs new file mode 100644 index 000000000..cdd58feeb --- /dev/null +++ b/core/src/ten_rust/tests/integration_test.rs @@ -0,0 +1,18 @@ +// +// This file is part of the TEN Framework project. +// See https://github.com/TEN-framework/ten_framework/LICENSE for license +// information. +// + +// Each file in the tests directory is a separate crate, and will be compiled as +// an executable. We need a all-in-one executable to run all the tests, and we +// will copy the all-in-one executable to the out directory. We use this main +// file to achieve this purpose. + +fn main() { + println!("Running integration tests of ten_rust..."); +} + +// Those following mods will be compiled in one executable. +mod graph_check; +mod interface; diff --git a/core/src/ten_rust/tests/interface.rs b/core/src/ten_rust/tests/interface.rs new file mode 100644 index 000000000..d0775457f --- /dev/null +++ b/core/src/ten_rust/tests/interface.rs @@ -0,0 +1,64 @@ +// +// This file is part of the TEN Framework project. +// See https://github.com/TEN-framework/ten_framework/LICENSE for license +// information. +// +use ten_rust::interface::ten_interface_schema_resolve_definition; + +#[test] +fn test_interface_ref_local() { + let content = r#" + [ + { + "name": "ia", + "cmd": [ + { + "name": "foo" + } + ] + }, + { + "name": "ib", + "$ref": "file://tests/test_data/interface/foo.json" + } + ] + "#; + + let result = ten_interface_schema_resolve_definition(content, "."); + assert!(result.is_ok()); + + let content_json = result.unwrap(); + assert_eq!(content_json.as_array().unwrap().len(), 2); + + let ib = content_json + .as_array() + .unwrap() + .get(1) + .unwrap() + .as_object() + .unwrap(); + assert!(ib.contains_key("cmd")) +} + +#[test] +fn test_interface_name_duplicated() { + let content = r#" + [ + { + "name": "ia", + "cmd": [ + { + "name": "foo" + } + ] + }, + { + "name": "ia", + "$ref": "file://tests/test_data/interface/foo.json" + } + ] + "#; + + let result = ten_interface_schema_resolve_definition(content, "."); + assert!(result.is_err()); +} diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/property.json b/core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/property.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/property.json rename to core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/property.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension/addon_1/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension/addon_1/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension/addon_1/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension/addon_1/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension/addon_2/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension/addon_2/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension/addon_2/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension/addon_2/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension_group/default_extension_group/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension_group/default_extension_group/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_all_types_incompatible/ten_packages/extension_group/default_extension_group/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_all_msgs_schema_incompatible/ten_packages/extension_group/default_extension_group/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/property.json b/core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/property.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/property.json rename to core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/property.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/ten_packages/extension_group/default_extension_group/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/ten_packages/extension_group/default_extension_group/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_graph_extension_not_installed/ten_packages/extension_group/default_extension_group/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_extension_not_installed/ten_packages/extension_group/default_extension_group/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/property.json b/core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/property.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/property.json rename to core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/property.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension/addon_a/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension/addon_a/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension/addon_a/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension/addon_a/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension/addon_b/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension/addon_b/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension/addon_b/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension/addon_b/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension_group/default_extension_group/manifest.json b/core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension_group/default_extension_group/manifest.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/check_predefined_graph_success/ten_packages/extension_group/default_extension_group/manifest.json rename to core/src/ten_rust/tests/test_data/graph_check_predefined_graph_success/ten_packages/extension_group/default_extension_group/manifest.json diff --git a/core/src/ten_rust/ten_rust_test_data/foo.json b/core/src/ten_rust/tests/test_data/interface/foo.json similarity index 100% rename from core/src/ten_rust/ten_rust_test_data/foo.json rename to core/src/ten_rust/tests/test_data/interface/foo.json