#!/usr/bin/env python3 """修复测试文件中的构造函数调用""" import re # 修复 account_role_test.go with open('tests/integration/account_role_test.go', 'r') as f: content = f.read() # 添加 shopRoleStore 初始化 content = re.sub( r'(\tenpriseStore := postgresStore\.NewEnterpriseStore\(env\.TX, env\.Redis\)\n)', r'\1\tshopRoleStore := postgresStore.NewShopRoleStore(env.TX, env.Redis)\n', content ) # 修复 accountService.New 调用 content = re.sub( r'accountService\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)', 'accountService.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)', content ) with open('tests/integration/account_role_test.go', 'w') as f: f.write(content) print("Fixed account_role_test.go") # 修复 role_assignment_limit_test.go with open('tests/unit/role_assignment_limit_test.go', 'r') as f: content = f.read() # 添加 shopRoleStore 初始化 content = re.sub( r'(\tenpriseStore := postgres\.NewEnterpriseStore\(tx, rdb\)\n)', r'\1\tshopRoleStore := postgres.NewShopRoleStore(tx, rdb)\n', content, count=1 # 只替换第一个 ) # 修复 account.New 调用 content = re.sub( r'account\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)', 'account.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)', content ) with open('tests/unit/role_assignment_limit_test.go', 'w') as f: f.write(content) print("Fixed role_assignment_limit_test.go") # 修复 permission_platform_filter_test.go with open('tests/unit/permission_platform_filter_test.go', 'r') as f: content = f.read() # 修复 permission.New 调用 - 需要添加 nil 作为第4个参数 (accountService) content = re.sub( r'permission\.New\(permissionStore, accountRoleStore, rolePermStore, rdb\)', 'permission.New(permissionStore, accountRoleStore, rolePermStore, nil, rdb)', content ) with open('tests/unit/permission_platform_filter_test.go', 'w') as f: f.write(content) print("Fixed permission_platform_filter_test.go") # 修复 account_audit_test.go with open('tests/integration/account_audit_test.go', 'r') as f: content = f.read() # 添加 shopRoleStore 初始化 content = re.sub( r'(\t\tenpriseStore := postgres\.NewEnterpriseStore\(env\.TX, env\.Redis\)\n)', r'\1\t\tshopRoleStore := postgres.NewShopRoleStore(env.TX, env.Redis)\n', content ) # 修复 accountSvc.New 调用 content = re.sub( r'accountSvc\.New\(accountStore, roleStore, accountRoleStore, shopStore, enterpriseStore, auditService\)', 'accountSvc.New(accountStore, roleStore, accountRoleStore, shopRoleStore, shopStore, enterpriseStore, auditService)', content ) with open('tests/integration/account_audit_test.go', 'w') as f: f.write(content) print("Fixed account_audit_test.go") print("\n所有文件修复完成!")