_fix_casbin.py 1.0 KB

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