| 123456789101112131415161718192021222324252627282930 |
- import os
- # Fix testenv.go: add missing Casbin rules
- testenv_path = r"test\testutil\testenv.go"
- with open(testenv_path, 'r', encoding='utf-8') as f:
- content = f.read()
- # Find the rules block and insert missing rules before the closing brace
- missing_rules = """\t\t// 黑白名单查询/更新/删除
- \t\t{"888", "/shortlist/queryShortlistList", "POST"},
- \t\t{"888", "/shortlist/updateShortlist", "PUT"},
- \t\t{"888", "/shortlist/deleteShortlist", "DELETE"},
- \t\t// 车辆类型管理
- \t\t{"888", "/vehicle/type/create", "POST"},
- \t\t{"888", "/vehicle/type/all", "GET"},
- """
- # Insert after the shortlist queryAllShortlists line
- old = '\t\t{"888", "/shortlist/queryAllShortlists", "GET"},\n'
- new = old + missing_rules
- if old in content:
- content = content.replace(new if False else old, new)
- print("Inserted missing Casbin rules")
- else:
- print("ERROR: Could not find insertion point in testenv.go")
- exit(1)
- with open(testenv_path, 'w', encoding='utf-8') as f:
- f.write(content)
- print(f"Updated testenv.go ({len(content)} bytes)")
|