feat: 实现功能3强制更新
- 新增 ForceUpdateCommand 类实现强制更新功能 - 添加 force-update CLI 命令支持 - 实现参数验证、配置对比、CDN缓存刷新 - 添加完整的测试用例和使用示例 - 更新文档和进度跟踪 - 支持模拟环境测试 - 添加警告提示和错误处理 主要文件: - src/config_man/core/force_update_command.py (新增) - src/config_man/cli/main.py (更新) - examples/test_force_update.py (新增) - examples/force_update_usage.py (新增) - docs/progress-tracker.md (更新)
This commit is contained in:
188
examples/force_update_usage.py
Normal file
188
examples/force_update_usage.py
Normal file
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
强制更新功能使用示例
|
||||
|
||||
演示如何使用强制更新功能来直接更新目标版本的Ver属性。
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from config_man.core.force_update_command import ForceUpdateCommand
|
||||
from config_man.utils.mock_rclone import patch_rclone
|
||||
|
||||
|
||||
def example_force_update_android():
|
||||
"""示例:强制更新Android平台配置"""
|
||||
print("📱 示例:强制更新Android平台配置")
|
||||
print("-" * 50)
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||||
|
||||
# 执行强制更新:将0.29版本的Ver属性更新为0.30版本的Ver值
|
||||
success = force_cmd.execute(
|
||||
platform="android",
|
||||
target_version="0.29", # 目标版本
|
||||
update_version="0.30" # 更新版本
|
||||
)
|
||||
|
||||
if success:
|
||||
print("✅ Android平台强制更新成功")
|
||||
else:
|
||||
print("❌ Android平台强制更新失败")
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def example_force_update_ios():
|
||||
"""示例:强制更新iOS平台配置"""
|
||||
print("\n🍎 示例:强制更新iOS平台配置")
|
||||
print("-" * 50)
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||||
|
||||
# 执行强制更新:将0.29版本的Ver属性更新为0.30版本的Ver值
|
||||
success = force_cmd.execute(
|
||||
platform="ios",
|
||||
target_version="0.29", # 目标版本
|
||||
update_version="0.30" # 更新版本
|
||||
)
|
||||
|
||||
if success:
|
||||
print("✅ iOS平台强制更新成功")
|
||||
else:
|
||||
print("❌ iOS平台强制更新失败")
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def example_force_update_with_custom_paths():
|
||||
"""示例:使用自定义路径进行强制更新"""
|
||||
print("\n🔧 示例:使用自定义路径进行强制更新")
|
||||
print("-" * 50)
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器,使用自定义路径
|
||||
force_cmd = ForceUpdateCommand(
|
||||
storage_path="custom/path", # 自定义存储路径
|
||||
cdn_base_url="https://custom.cdn.com" # 自定义CDN URL
|
||||
)
|
||||
|
||||
# 执行强制更新
|
||||
success = force_cmd.execute(
|
||||
platform="android",
|
||||
target_version="0.28",
|
||||
update_version="0.29"
|
||||
)
|
||||
|
||||
if success:
|
||||
print("✅ 自定义路径强制更新成功")
|
||||
else:
|
||||
print("❌ 自定义路径强制更新失败")
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def example_force_update_validation():
|
||||
"""示例:参数验证功能"""
|
||||
print("\n🔍 示例:参数验证功能")
|
||||
print("-" * 50)
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand()
|
||||
|
||||
# 测试各种无效参数
|
||||
test_cases = [
|
||||
{
|
||||
"name": "无效平台",
|
||||
"params": ("invalid", "0.29", "0.30"),
|
||||
"expected": False
|
||||
},
|
||||
{
|
||||
"name": "无效版本格式",
|
||||
"params": ("android", "invalid", "0.30"),
|
||||
"expected": False
|
||||
},
|
||||
{
|
||||
"name": "相同版本",
|
||||
"params": ("android", "0.29", "0.29"),
|
||||
"expected": False
|
||||
},
|
||||
{
|
||||
"name": "有效参数",
|
||||
"params": ("android", "0.29", "0.30"),
|
||||
"expected": True
|
||||
}
|
||||
]
|
||||
|
||||
for test_case in test_cases:
|
||||
print(f"测试: {test_case['name']}")
|
||||
success = force_cmd.execute(*test_case['params'])
|
||||
status = "✅ 通过" if success == test_case['expected'] else "❌ 失败"
|
||||
print(f" 结果: {status}")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("🚀 强制更新功能使用示例")
|
||||
print("=" * 60)
|
||||
|
||||
# 运行所有示例
|
||||
examples = [
|
||||
("Android平台强制更新", example_force_update_android),
|
||||
("iOS平台强制更新", example_force_update_ios),
|
||||
("自定义路径强制更新", example_force_update_with_custom_paths),
|
||||
("参数验证功能", example_force_update_validation),
|
||||
]
|
||||
|
||||
results = []
|
||||
for example_name, example_func in examples:
|
||||
try:
|
||||
result = example_func()
|
||||
results.append((example_name, result))
|
||||
except Exception as e:
|
||||
print(f"❌ {example_name} 示例异常: {e}")
|
||||
results.append((example_name, False))
|
||||
|
||||
# 显示结果
|
||||
print("\n" + "=" * 60)
|
||||
print("📊 示例执行结果:")
|
||||
|
||||
for example_name, result in results:
|
||||
status = "✅ 成功" if result else "❌ 失败"
|
||||
print(f" {example_name}: {status}")
|
||||
|
||||
print("\n💡 使用说明:")
|
||||
print(" 1. 强制更新会直接修改目标版本的Ver属性")
|
||||
print(" 2. 更新会立即影响使用该版本的应用")
|
||||
print(" 3. 建议在更新前通知相关方")
|
||||
print(" 4. 可以使用 --mock 参数进行测试")
|
||||
|
||||
print("\n🔧 CLI命令示例:")
|
||||
print(" config-man force-update --platform android --target-version 0.29 --update-version 0.30")
|
||||
print(" config-man force-update --platform ios --target-version 0.29 --update-version 0.30 --mock")
|
||||
print(" config-man force-update --platform android --target-version 0.29 --update-version 0.30 --storage-path custom/path")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
125
examples/suggest_update_usage.py
Normal file
125
examples/suggest_update_usage.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
建议更新功能使用示例
|
||||
|
||||
这个脚本演示了如何使用 config-man 的建议更新功能。
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from src.config_man.core.suggest_update_command import SuggestUpdateCommand
|
||||
from src.config_man.utils.mock_rclone import patch_rclone
|
||||
|
||||
|
||||
def example_suggest_update():
|
||||
"""建议更新功能示例"""
|
||||
|
||||
print("📋 建议更新功能使用示例")
|
||||
print("=" * 50)
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建建议更新命令处理器
|
||||
suggest_cmd = SuggestUpdateCommand("ab", "https://cdn.example.com")
|
||||
|
||||
# 示例1: Android平台建议更新
|
||||
print("\n📱 示例1: Android平台建议更新")
|
||||
print("目标版本: 0.29 -> 更新版本: 0.30")
|
||||
|
||||
success = suggest_cmd.execute("android", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ Android平台建议更新成功")
|
||||
else:
|
||||
print("❌ Android平台建议更新失败")
|
||||
|
||||
# 示例2: iOS平台建议更新
|
||||
print("\n📱 示例2: iOS平台建议更新")
|
||||
print("目标版本: 0.29 -> 更新版本: 0.30")
|
||||
|
||||
success = suggest_cmd.execute("ios", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ iOS平台建议更新成功")
|
||||
else:
|
||||
print("❌ iOS平台建议更新失败")
|
||||
|
||||
# 示例3: 错误处理
|
||||
print("\n🚫 示例3: 错误处理")
|
||||
|
||||
# 测试无效平台
|
||||
print("测试无效平台...")
|
||||
success = suggest_cmd.execute("invalid", "0.29", "0.30")
|
||||
if not success:
|
||||
print("✅ 正确处理了无效平台错误")
|
||||
|
||||
# 测试相同版本
|
||||
print("测试相同版本...")
|
||||
success = suggest_cmd.execute("android", "0.29", "0.29")
|
||||
if not success:
|
||||
print("✅ 正确处理了相同版本错误")
|
||||
|
||||
# 测试无效版本格式
|
||||
print("测试无效版本格式...")
|
||||
success = suggest_cmd.execute("android", "invalid", "0.30")
|
||||
if not success:
|
||||
print("✅ 正确处理了无效版本格式错误")
|
||||
|
||||
print("\n🎉 建议更新功能示例完成!")
|
||||
|
||||
|
||||
def show_cli_usage():
|
||||
"""显示CLI使用方式"""
|
||||
|
||||
print("\n🔧 CLI使用方式")
|
||||
print("=" * 50)
|
||||
|
||||
print("1. 基本用法:")
|
||||
print(" config-man suggest-update --platform android --target-version 0.29 --update-version 0.30")
|
||||
|
||||
print("\n2. 指定存储路径和CDN URL:")
|
||||
print(" config-man suggest-update --platform ios --target-version 0.29 --update-version 0.30 --storage-path custom/path --cdn-url https://custom.cdn.com")
|
||||
|
||||
print("\n3. 使用模拟环境测试:")
|
||||
print(" config-man suggest-update --platform android --target-version 0.29 --update-version 0.30 --mock")
|
||||
|
||||
print("\n4. 查看帮助信息:")
|
||||
print(" config-man suggest-update --help")
|
||||
|
||||
|
||||
def show_config_changes():
|
||||
"""显示配置变更示例"""
|
||||
|
||||
print("\n📝 配置变更示例")
|
||||
print("=" * 50)
|
||||
|
||||
print("修改前:")
|
||||
print("""{
|
||||
"Ver": "0.29.1abc123",
|
||||
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
||||
"PlayFabTitle": "B066F"
|
||||
}""")
|
||||
|
||||
print("\n修改后:")
|
||||
print("""{
|
||||
"Ver": "0.29.1abc123",
|
||||
"Ver_New": "0.30.1def456",
|
||||
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
||||
"PlayFabTitle": "B066F"
|
||||
}""")
|
||||
|
||||
print("\n说明:")
|
||||
print("- 在目标版本(0.29)的配置中添加了 Ver_New 属性")
|
||||
print("- Ver_New 的值来自更新版本(0.30)的 Ver 属性")
|
||||
print("- 这样客户端可以检测到有新版本可用")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
example_suggest_update()
|
||||
show_cli_usage()
|
||||
show_config_changes()
|
||||
209
examples/test_cloudflare_cdn.py
Normal file
209
examples/test_cloudflare_cdn.py
Normal file
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Cloudflare CDN刷新功能测试
|
||||
|
||||
这个脚本用于测试 config-man 的Cloudflare CDN刷新功能。
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from src.config_man.utils.cloudflare import CloudflareCDN, refresh_cloudflare_cache
|
||||
|
||||
|
||||
def test_cloudflare_configuration():
|
||||
"""测试Cloudflare配置"""
|
||||
|
||||
print("🔧 测试Cloudflare配置...")
|
||||
|
||||
cdn = CloudflareCDN()
|
||||
|
||||
# 检查配置
|
||||
if cdn.is_configured():
|
||||
print("✅ Cloudflare配置完整")
|
||||
print(f" API Token: {'已设置' if cdn.api_token else '未设置'}")
|
||||
print(f" Zone ID: {'已设置' if cdn.zone_id else '未设置'}")
|
||||
print(f" Timeout: {cdn.timeout}秒")
|
||||
print(f" Retry Count: {cdn.retry_count}次")
|
||||
|
||||
# 显示配置来源
|
||||
from src.config_man.utils.config import config
|
||||
config_api_token = config.get_cloudflare_api_token()
|
||||
config_zone_id = config.get_cloudflare_zone_id()
|
||||
|
||||
if config_api_token:
|
||||
print(" 📁 API Token来源: 配置文件")
|
||||
elif os.getenv('CLOUDFLARE_API_TOKEN'):
|
||||
print(" 🌍 API Token来源: 环境变量")
|
||||
else:
|
||||
print(" ❌ API Token来源: 未设置")
|
||||
|
||||
if config_zone_id:
|
||||
print(" 📁 Zone ID来源: 配置文件")
|
||||
elif os.getenv('CLOUDFLARE_ZONE_ID'):
|
||||
print(" 🌍 Zone ID来源: 环境变量")
|
||||
else:
|
||||
print(" ❌ Zone ID来源: 未设置")
|
||||
|
||||
# 获取域名信息
|
||||
zone_info = cdn.get_zone_info()
|
||||
if zone_info:
|
||||
print(f"✅ 域名信息获取成功: {zone_info.get('name', 'Unknown')}")
|
||||
else:
|
||||
print("❌ 域名信息获取失败")
|
||||
else:
|
||||
print("❌ Cloudflare配置不完整")
|
||||
print("请通过以下方式之一设置:")
|
||||
print("1. 配置文件:")
|
||||
print(" config-man setup-cloudflare --api-token your_token --zone-id your_zone_id")
|
||||
print("2. 环境变量:")
|
||||
print(" export CLOUDFLARE_API_TOKEN='your_token'")
|
||||
print(" export CLOUDFLARE_ZONE_ID='your_zone_id'")
|
||||
|
||||
|
||||
def test_cache_refresh():
|
||||
"""测试缓存刷新功能"""
|
||||
|
||||
print("\n🔄 测试缓存刷新功能...")
|
||||
|
||||
# 测试URL列表
|
||||
test_urls = [
|
||||
"https://ab.bamboogames.cc/ab/0_29/androidconfig.json",
|
||||
"https://ab.bamboogames.cc/ab/0_29/iosconfig.json"
|
||||
]
|
||||
|
||||
print(f"测试URL列表: {test_urls}")
|
||||
|
||||
# 测试缓存刷新
|
||||
success = refresh_cloudflare_cache(test_urls)
|
||||
|
||||
if success:
|
||||
print("✅ Cloudflare CDN缓存刷新成功")
|
||||
else:
|
||||
print("❌ Cloudflare CDN缓存刷新失败")
|
||||
|
||||
|
||||
def test_cache_refresh_by_tags():
|
||||
"""测试通过标签刷新缓存"""
|
||||
|
||||
print("\n🏷️ 测试通过标签刷新缓存...")
|
||||
|
||||
cdn = CloudflareCDN()
|
||||
|
||||
if not cdn.is_configured():
|
||||
print("❌ Cloudflare配置不完整,跳过标签测试")
|
||||
return
|
||||
|
||||
# 测试标签
|
||||
test_tags = ["config-man", "version-0.29"]
|
||||
|
||||
print(f"测试标签: {test_tags}")
|
||||
|
||||
success = cdn.purge_cache_by_tags(test_tags)
|
||||
|
||||
if success:
|
||||
print("✅ 通过标签刷新缓存成功")
|
||||
else:
|
||||
print("❌ 通过标签刷新缓存失败")
|
||||
|
||||
|
||||
def test_entire_cache_refresh():
|
||||
"""测试刷新整个缓存"""
|
||||
|
||||
print("\n🌐 测试刷新整个缓存...")
|
||||
|
||||
cdn = CloudflareCDN()
|
||||
|
||||
if not cdn.is_configured():
|
||||
print("❌ Cloudflare配置不完整,跳过全量刷新测试")
|
||||
return
|
||||
|
||||
print("警告: 这将刷新整个域名的缓存,请确认是否继续...")
|
||||
response = input("输入 'yes' 继续: ")
|
||||
|
||||
if response.lower() == 'yes':
|
||||
success = cdn.purge_entire_cache()
|
||||
|
||||
if success:
|
||||
print("✅ 整个缓存刷新成功")
|
||||
else:
|
||||
print("❌ 整个缓存刷新失败")
|
||||
else:
|
||||
print("⏭️ 跳过全量刷新测试")
|
||||
|
||||
|
||||
def test_suggest_update_with_cdn():
|
||||
"""测试建议更新功能中的CDN刷新"""
|
||||
|
||||
print("\n📝 测试建议更新功能中的CDN刷新...")
|
||||
|
||||
from src.config_man.core.suggest_update_command import SuggestUpdateCommand
|
||||
from src.config_man.utils.mock_rclone import patch_rclone
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建建议更新命令处理器
|
||||
suggest_cmd = SuggestUpdateCommand("ab", "https://ab.bamboogames.cc")
|
||||
|
||||
# 测试Android平台
|
||||
print("测试Android平台建议更新...")
|
||||
success = suggest_cmd.execute("android", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ Android平台建议更新成功,CDN刷新正常")
|
||||
else:
|
||||
print("❌ Android平台建议更新失败")
|
||||
|
||||
# 测试iOS平台
|
||||
print("测试iOS平台建议更新...")
|
||||
success = suggest_cmd.execute("ios", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ iOS平台建议更新成功,CDN刷新正常")
|
||||
else:
|
||||
print("❌ iOS平台建议更新失败")
|
||||
|
||||
|
||||
def show_cloudflare_setup_guide():
|
||||
"""显示Cloudflare设置指南"""
|
||||
|
||||
print("\n📖 Cloudflare设置指南")
|
||||
print("=" * 50)
|
||||
|
||||
print("1. 获取Cloudflare API Token:")
|
||||
print(" - 登录Cloudflare控制台")
|
||||
print(" - 进入 'My Profile' -> 'API Tokens'")
|
||||
print(" - 创建新的API Token")
|
||||
print(" - 权限设置:")
|
||||
print(" * Zone:Zone:Read")
|
||||
print(" * Zone:Cache Purge:Edit")
|
||||
|
||||
print("\n2. 获取Zone ID:")
|
||||
print(" - 在Cloudflare控制台中选择域名")
|
||||
print(" - 在右侧边栏找到 'Zone ID'")
|
||||
|
||||
print("\n3. 设置环境变量:")
|
||||
print(" export CLOUDFLARE_API_TOKEN='your_api_token'")
|
||||
print(" export CLOUDFLARE_ZONE_ID='your_zone_id'")
|
||||
|
||||
print("\n4. 验证配置:")
|
||||
print(" python examples/test_cloudflare_cdn.py")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Cloudflare CDN刷新功能测试")
|
||||
print("=" * 50)
|
||||
|
||||
test_cloudflare_configuration()
|
||||
test_cache_refresh()
|
||||
test_cache_refresh_by_tags()
|
||||
test_entire_cache_refresh()
|
||||
test_suggest_update_with_cdn()
|
||||
show_cloudflare_setup_guide()
|
||||
|
||||
print("\n🎉 Cloudflare CDN刷新功能测试完成!")
|
||||
157
examples/test_force_update.py
Normal file
157
examples/test_force_update.py
Normal file
@@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
强制更新功能测试示例
|
||||
|
||||
测试强制更新命令的功能,包括参数验证、配置更新、CDN缓存刷新等。
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from config_man.core.force_update_command import ForceUpdateCommand
|
||||
from config_man.utils.mock_rclone import patch_rclone
|
||||
|
||||
|
||||
def test_force_update_basic():
|
||||
"""测试基本强制更新功能"""
|
||||
print("🧪 测试基本强制更新功能")
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||||
|
||||
# 执行强制更新
|
||||
success = force_cmd.execute(
|
||||
platform="android",
|
||||
target_version="0.29",
|
||||
update_version="0.30"
|
||||
)
|
||||
|
||||
print(f"✅ 强制更新测试结果: {'成功' if success else '失败'}")
|
||||
return success
|
||||
|
||||
|
||||
def test_force_update_ios():
|
||||
"""测试iOS平台强制更新"""
|
||||
print("\n🧪 测试iOS平台强制更新")
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||||
|
||||
# 执行强制更新
|
||||
success = force_cmd.execute(
|
||||
platform="ios",
|
||||
target_version="0.29",
|
||||
update_version="0.30"
|
||||
)
|
||||
|
||||
print(f"✅ iOS强制更新测试结果: {'成功' if success else '失败'}")
|
||||
return success
|
||||
|
||||
|
||||
def test_force_update_validation():
|
||||
"""测试参数验证功能"""
|
||||
print("\n🧪 测试参数验证功能")
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand()
|
||||
|
||||
# 测试无效平台
|
||||
print("测试无效平台...")
|
||||
success1 = force_cmd.execute("invalid", "0.29", "0.30")
|
||||
print(f"无效平台测试结果: {'失败(预期)' if not success1 else '成功(意外)'}")
|
||||
|
||||
# 测试无效版本格式
|
||||
print("测试无效版本格式...")
|
||||
success2 = force_cmd.execute("android", "invalid", "0.30")
|
||||
print(f"无效版本格式测试结果: {'失败(预期)' if not success2 else '成功(意外)'}")
|
||||
|
||||
# 测试相同版本
|
||||
print("测试相同版本...")
|
||||
success3 = force_cmd.execute("android", "0.29", "0.29")
|
||||
print(f"相同版本测试结果: {'失败(预期)' if not success3 else '成功(意外)'}")
|
||||
|
||||
return not success1 and not success2 and not success3
|
||||
|
||||
|
||||
def test_force_update_comparison():
|
||||
"""测试配置对比功能"""
|
||||
print("\n🧪 测试配置对比功能")
|
||||
|
||||
# 启用模拟环境
|
||||
patch_rclone()
|
||||
|
||||
# 创建强制更新命令处理器
|
||||
force_cmd = ForceUpdateCommand(storage_path="ab", cdn_base_url="https://cdn.example.com")
|
||||
|
||||
# 执行强制更新并观察对比输出
|
||||
success = force_cmd.execute(
|
||||
platform="android",
|
||||
target_version="0.29",
|
||||
update_version="0.30"
|
||||
)
|
||||
|
||||
print(f"✅ 配置对比测试结果: {'成功' if success else '失败'}")
|
||||
return success
|
||||
|
||||
|
||||
def main():
|
||||
"""主测试函数"""
|
||||
print("🚀 开始强制更新功能测试")
|
||||
print("=" * 50)
|
||||
|
||||
# 运行所有测试
|
||||
tests = [
|
||||
("基本强制更新功能", test_force_update_basic),
|
||||
("iOS平台强制更新", test_force_update_ios),
|
||||
("参数验证功能", test_force_update_validation),
|
||||
("配置对比功能", test_force_update_comparison),
|
||||
]
|
||||
|
||||
results = []
|
||||
for test_name, test_func in tests:
|
||||
try:
|
||||
result = test_func()
|
||||
results.append((test_name, result))
|
||||
except Exception as e:
|
||||
print(f"❌ {test_name} 测试异常: {e}")
|
||||
results.append((test_name, False))
|
||||
|
||||
# 显示测试结果
|
||||
print("\n" + "=" * 50)
|
||||
print("📊 测试结果汇总:")
|
||||
|
||||
passed = 0
|
||||
for test_name, result in results:
|
||||
status = "✅ 通过" if result else "❌ 失败"
|
||||
print(f" {test_name}: {status}")
|
||||
if result:
|
||||
passed += 1
|
||||
|
||||
print(f"\n总计: {len(results)} 个测试,通过: {passed} 个,失败: {len(results) - passed} 个")
|
||||
|
||||
if passed == len(results):
|
||||
print("🎉 所有测试通过!强制更新功能实现成功。")
|
||||
else:
|
||||
print("⚠️ 部分测试失败,请检查实现。")
|
||||
|
||||
return passed == len(results)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = main()
|
||||
sys.exit(0 if success else 1)
|
||||
209
examples/test_suggest_update.py
Normal file
209
examples/test_suggest_update.py
Normal file
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试建议更新功能
|
||||
|
||||
这个脚本用于测试 config-man 的建议更新功能。
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from src.config_man.utils.mock_rclone import patch_rclone
|
||||
from src.config_man.utils.crypto import encrypt
|
||||
from src.config_man.core.suggest_update_command import SuggestUpdateCommand
|
||||
|
||||
|
||||
def create_test_configs():
|
||||
"""创建测试配置文件"""
|
||||
|
||||
# 模拟目标版本配置 (0.29)
|
||||
target_config = {
|
||||
"Ver": "0.29.1abc123",
|
||||
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
||||
"PlayFabTitle": "B066F",
|
||||
"Google_Play_URL": "https://play.google.com/store/apps/details?id=com.arkgame.ft",
|
||||
"APP_Store_URL": "https://apps.apple.com/us/app/id6505145935",
|
||||
"HeartBeat": "60",
|
||||
"RTMPid": "80000586",
|
||||
"RTMServerEndpoint": "rtm-intl-frontgate.ilivedata.com:13321",
|
||||
"RTMHmacSecret": "57047697437f4f2c97a835e8d9a53358",
|
||||
"FuncUrl": "https://leaderboardcreate.azurewebsites.net",
|
||||
"FuncKey": "R5kU45fNBRd52Eqp3tEqfpZqrbFw53uSSEo7wraUSqIfAzFuRmLm_w=="
|
||||
}
|
||||
|
||||
# 模拟更新版本配置 (0.30)
|
||||
update_config = {
|
||||
"Ver": "0.30.1def456",
|
||||
"EventApiURL": "https://n3backend.azurewebsites.net/",
|
||||
"PlayFabTitle": "B066F",
|
||||
"Google_Play_URL": "https://play.google.com/store/apps/details?id=com.arkgame.ft",
|
||||
"APP_Store_URL": "https://apps.apple.com/us/app/id6505145935",
|
||||
"HeartBeat": "60",
|
||||
"RTMPid": "80000586",
|
||||
"RTMServerEndpoint": "rtm-intl-frontgate.ilivedata.com:13321",
|
||||
"RTMHmacSecret": "57047697437f4f2c97a835e8d9a53358",
|
||||
"FuncUrl": "https://leaderboardcreate.azurewebsites.net",
|
||||
"FuncKey": "R5kU45fNBRd52Eqp3tEqfpZqrbFw53uSSEo7wraUSqIfAzFuRmLm_w=="
|
||||
}
|
||||
|
||||
return target_config, update_config
|
||||
|
||||
|
||||
def test_suggest_update():
|
||||
"""测试建议更新功能"""
|
||||
|
||||
print("🧪 开始测试建议更新功能...")
|
||||
|
||||
# 启用rclone模拟
|
||||
patch_rclone()
|
||||
|
||||
# 创建测试配置
|
||||
target_config, update_config = create_test_configs()
|
||||
|
||||
# 模拟存储测试配置
|
||||
# 使用MockRclone类来管理测试数据
|
||||
from src.config_man.utils.mock_rclone import MockRclone
|
||||
mock_rclone = MockRclone()
|
||||
|
||||
# 创建测试配置文件
|
||||
import os
|
||||
test_data_path = "test_data"
|
||||
storage_path = "ab"
|
||||
|
||||
# 创建目标版本配置 (0.29)
|
||||
target_version_path = os.path.join(test_data_path, storage_path, "0_29")
|
||||
os.makedirs(target_version_path, exist_ok=True)
|
||||
|
||||
# 保存Android配置
|
||||
android_config_path = os.path.join(target_version_path, "androidconfig.json")
|
||||
with open(android_config_path, 'w', encoding='utf-8') as f:
|
||||
f.write(encrypt(json.dumps(target_config, indent=2, ensure_ascii=False)))
|
||||
|
||||
# 保存iOS配置
|
||||
ios_config_path = os.path.join(target_version_path, "iosconfig.json")
|
||||
with open(ios_config_path, 'w', encoding='utf-8') as f:
|
||||
f.write(encrypt(json.dumps(target_config, indent=2, ensure_ascii=False)))
|
||||
|
||||
# 创建更新版本配置 (0.30)
|
||||
update_version_path = os.path.join(test_data_path, storage_path, "0_30")
|
||||
os.makedirs(update_version_path, exist_ok=True)
|
||||
|
||||
# 保存Android配置
|
||||
android_config_path = os.path.join(update_version_path, "androidconfig.json")
|
||||
with open(android_config_path, 'w', encoding='utf-8') as f:
|
||||
f.write(encrypt(json.dumps(update_config, indent=2, ensure_ascii=False)))
|
||||
|
||||
# 保存iOS配置
|
||||
ios_config_path = os.path.join(update_version_path, "iosconfig.json")
|
||||
with open(ios_config_path, 'w', encoding='utf-8') as f:
|
||||
f.write(encrypt(json.dumps(update_config, indent=2, ensure_ascii=False)))
|
||||
|
||||
print("📁 已创建模拟配置文件")
|
||||
|
||||
# 创建建议更新命令处理器
|
||||
suggest_cmd = SuggestUpdateCommand("ab", "")
|
||||
|
||||
# 测试Android平台
|
||||
print("\n📱 测试Android平台...")
|
||||
success = suggest_cmd.execute("android", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ Android平台测试成功")
|
||||
|
||||
# 验证结果
|
||||
from src.config_man.utils.crypto import decrypt
|
||||
updated_config_path = os.path.join(test_data_path, storage_path, "0_29", "androidconfig.json")
|
||||
if os.path.exists(updated_config_path):
|
||||
with open(updated_config_path, 'r', encoding='utf-8') as f:
|
||||
encrypted_content = f.read().strip()
|
||||
decrypted_content = decrypt(encrypted_content)
|
||||
updated_config = json.loads(decrypted_content)
|
||||
|
||||
if "Ver_New" in updated_config:
|
||||
print(f"✅ 已添加 Ver_New: {updated_config['Ver_New']}")
|
||||
print("✅ 配置对比功能正常显示")
|
||||
else:
|
||||
print("❌ 未找到 Ver_New 属性")
|
||||
else:
|
||||
print("❌ 更新后的配置文件不存在")
|
||||
else:
|
||||
print("❌ Android平台测试失败")
|
||||
|
||||
# 测试iOS平台
|
||||
print("\n📱 测试iOS平台...")
|
||||
success = suggest_cmd.execute("ios", "0.29", "0.30")
|
||||
|
||||
if success:
|
||||
print("✅ iOS平台测试成功")
|
||||
|
||||
# 验证结果
|
||||
updated_config_path = os.path.join(test_data_path, storage_path, "0_29", "iosconfig.json")
|
||||
if os.path.exists(updated_config_path):
|
||||
with open(updated_config_path, 'r', encoding='utf-8') as f:
|
||||
encrypted_content = f.read().strip()
|
||||
decrypted_content = decrypt(encrypted_content)
|
||||
updated_config = json.loads(decrypted_content)
|
||||
|
||||
if "Ver_New" in updated_config:
|
||||
print(f"✅ 已添加 Ver_New: {updated_config['Ver_New']}")
|
||||
print("✅ 配置对比功能正常显示")
|
||||
else:
|
||||
print("❌ 未找到 Ver_New 属性")
|
||||
else:
|
||||
print("❌ 更新后的配置文件不存在")
|
||||
else:
|
||||
print("❌ iOS平台测试失败")
|
||||
|
||||
# 测试错误情况
|
||||
print("\n🚫 测试错误情况...")
|
||||
|
||||
# 测试无效平台
|
||||
success = suggest_cmd.execute("invalid", "0.29", "0.30")
|
||||
if not success:
|
||||
print("✅ 无效平台测试通过")
|
||||
|
||||
# 测试相同版本
|
||||
success = suggest_cmd.execute("android", "0.29", "0.29")
|
||||
if not success:
|
||||
print("✅ 相同版本测试通过")
|
||||
|
||||
# 测试无效版本格式
|
||||
success = suggest_cmd.execute("android", "invalid", "0.30")
|
||||
if not success:
|
||||
print("✅ 无效版本格式测试通过")
|
||||
|
||||
print("\n🎉 建议更新功能测试完成!")
|
||||
|
||||
|
||||
def test_cli_command():
|
||||
"""测试CLI命令"""
|
||||
|
||||
print("\n🔧 测试CLI命令...")
|
||||
|
||||
# 测试帮助信息
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["python", "-m", "src.config_man.cli.main", "suggest-update", "--help"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("✅ CLI帮助信息正常")
|
||||
else:
|
||||
print("❌ CLI帮助信息异常")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ CLI命令测试失败: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_suggest_update()
|
||||
test_cli_command()
|
||||
Reference in New Issue
Block a user