-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add more test cases for local dependency (#515)
- Loading branch information
Showing
9 changed files
with
184 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/ten_manager/install_all/local_dependency_link_in_extension/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# Copyright © 2025 Agora | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0, with certain conditions. | ||
# Refer to the "LICENSE" file in the root directory for more information. | ||
# | ||
import("//build/ten_runtime/feature/test.gni") | ||
|
||
ten_package_test_prepare_auxiliary_resources( | ||
"local_dependency_link_in_extension") { | ||
resources = [ | ||
"//.gnfiles/build/scripts/cmd_exec.py=>common/cmd_exec.py", | ||
"__init__.py", | ||
"test_app", | ||
"test_case.py", | ||
] | ||
deps = [ | ||
"//core/src/ten_manager", | ||
"//tests/local_registry", | ||
] | ||
} |
Empty file.
6 changes: 6 additions & 0 deletions
6
...ten_manager/install_all/local_dependency_link_in_extension/test_app/local_c/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "extension", | ||
"name": "ext_c", | ||
"version": "3.0.0", | ||
"dependencies": [] | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ten_manager/install_all/local_dependency_link_in_extension/test_app/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"type": "app", | ||
"name": "test_app", | ||
"version": "1.0.0", | ||
"dependencies": [ | ||
{ | ||
"type": "extension", | ||
"name": "ext_1", | ||
"version": "3.0.0" | ||
}, | ||
{ | ||
"type": "extension", | ||
"name": "local_d", | ||
"version": "3.0.0" | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
.../local_dependency_link_in_extension/test_app/ten_packages/extension/local_d/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"type": "extension", | ||
"name": "local_d", | ||
"version": "3.0.0", | ||
"dependencies": [ | ||
{ | ||
"path": "../../../local_c" | ||
} | ||
] | ||
} |
110 changes: 110 additions & 0 deletions
110
tests/ten_manager/install_all/local_dependency_link_in_extension/test_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# | ||
# Copyright © 2025 Agora | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0, with certain conditions. | ||
# Refer to the "LICENSE" file in the root directory for more information. | ||
# | ||
import os | ||
import sys | ||
from .common import cmd_exec | ||
|
||
|
||
def get_installed_extensions_count(app_dir: str): | ||
extension_dir = os.path.join(app_dir, "ten_packages/extension/") | ||
extensions = os.listdir(extension_dir) | ||
|
||
return len(extensions) | ||
|
||
|
||
def normalize_path(path): | ||
if path.startswith("\\\\?\\"): | ||
return path[4:] | ||
return path | ||
|
||
|
||
def test_tman_dependency_resolve(): | ||
base_path = os.path.dirname(os.path.abspath(__file__)) | ||
root_dir = os.path.join(base_path, "../../../../") | ||
|
||
if sys.platform == "win32": | ||
os.environ["PATH"] = ( | ||
os.path.join(root_dir, "ten_manager/lib") + ";" + os.getenv("PATH") | ||
) | ||
tman_bin = os.path.join(root_dir, "ten_manager/bin/tman.exe") | ||
else: | ||
tman_bin = os.path.join(root_dir, "ten_manager/bin/tman") | ||
|
||
app_dir = os.path.join(base_path, "test_app") | ||
|
||
config_file = os.path.join( | ||
root_dir, | ||
"tests/local_registry/config.json", | ||
) | ||
|
||
returncode, output_text = cmd_exec.run_cmd_realtime( | ||
[ | ||
tman_bin, | ||
f"--config-file={config_file}", | ||
"install", | ||
], | ||
cwd=app_dir, | ||
) | ||
if returncode != 0: | ||
print(output_text) | ||
assert False | ||
|
||
installed_count = get_installed_extensions_count(app_dir) | ||
assert ( | ||
installed_count == 3 | ||
), f"Expected 2 extensions, found {installed_count}." | ||
|
||
ext_c_path = os.path.join(app_dir, "ten_packages/extension/ext_c") | ||
local_c_path = os.path.join(app_dir, "local_c") | ||
|
||
# Check if `ext_c_path` exists. | ||
assert os.path.exists( | ||
ext_c_path | ||
), f"Expected ext_c path '{ext_c_path}' does not exist." | ||
|
||
# Check if `ext_c_path` is a symbolic link. | ||
is_symlink = os.path.islink(ext_c_path) | ||
assert is_symlink, f"Expected '{ext_c_path}' to be a symbolic link." | ||
|
||
# Retrieve the target path of the symbolic link. | ||
try: | ||
symlink_target = os.readlink(ext_c_path) | ||
except OSError as e: | ||
assert False, f"Failed to read symbolic link '{ext_c_path}': {e}" | ||
|
||
# If `symlink_target` is a relative path, it needs to be converted to an | ||
# absolute path. | ||
if not os.path.isabs(symlink_target): | ||
symlink_target = os.path.normpath( | ||
os.path.join(os.path.dirname(ext_c_path), symlink_target) | ||
) | ||
|
||
# Normalize the path to eliminate any redundancies (e.g., `./`). | ||
symlink_target = os.path.normpath(symlink_target) | ||
expected_target = os.path.normpath(local_c_path) | ||
|
||
# On Windows, `os.readlink` may return paths with backslashes, so it's | ||
# necessary to standardize the path separators. | ||
symlink_target = os.path.abspath(symlink_target) | ||
expected_target = os.path.abspath(expected_target) | ||
|
||
# Normalize paths by removing '\\?\' prefix if present | ||
symlink_target = normalize_path(symlink_target) | ||
expected_target = normalize_path(expected_target) | ||
|
||
assert symlink_target == expected_target, ( | ||
f"Symbolic link target mismatch for '{ext_c_path}'. " | ||
f"Expected: '{expected_target}', Found: '{symlink_target}'." | ||
) | ||
|
||
print( | ||
f"Symbolic link '{ext_c_path}' correctly points to '{symlink_target}'." | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_tman_dependency_resolve() |