gen_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package permisgen
  2. import (
  3. "Cold_Logistic/internal/pkg/common/global"
  4. "Cold_Logistic/internal/pkg/common/options"
  5. "Cold_Logistic/internal/server/infra/dao"
  6. "context"
  7. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/database/myorm"
  8. "testing"
  9. )
  10. func init() {
  11. options.OptInstance = &options.Options{
  12. DB: &myorm.DBOption{
  13. Dialect: "mysql",
  14. Host: "192.168.11.23",
  15. Port: 3306,
  16. Db: "cc_logistic",
  17. UserName: "cc_logistic",
  18. Password: "7MBaLDh8ZjBTHwCR",
  19. OtherParams: "charset=utf8mb4&parseTime=True&loc=Local",
  20. MaxIdleConn: 20,
  21. MaxOpenConn: 200,
  22. ConnMaxLifetime: 60,
  23. },
  24. }
  25. global.CommonConnectRepoInst = global.NewCommonConnectsRepo(options.OptInstance)
  26. global.CommonConnectRepoInst.StoreDB = myorm.InitMysql(*options.OptInstance.DB)
  27. }
  28. func Test_Region(t *testing.T) {
  29. store := dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)
  30. ctx := context.Background()
  31. err := store.InTx(ctx, func(ctx context.Context) error {
  32. all, err := store.Region().FindAll(context.Background())
  33. if err != nil {
  34. return err
  35. }
  36. res := make([]*RegionFiled, 0)
  37. res = buildRegionTree(res, all)
  38. err = NewRegionGen(store).Run(ctx, res)
  39. if err != nil {
  40. return err
  41. }
  42. return nil
  43. })
  44. if err != nil {
  45. t.Errorf("err: %v", err)
  46. return
  47. }
  48. t.Log("成功")
  49. }