d_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package dao
  2. import (
  3. "encoding/hex"
  4. "flag"
  5. "os"
  6. "strconv"
  7. "strings"
  8. "testing"
  9. "go-common/app/interface/main/push-archive/conf"
  10. "github.com/smartystreets/goconvey/convey"
  11. )
  12. var d *Dao
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.archive.push-archive")
  16. flag.Set("conf_token", "61c0d7d8527e8a4aad5b49826869e23c")
  17. flag.Set("tree_id", "7615")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../cmd/push-archive-test.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. os.Exit(m.Run())
  33. }
  34. func Test_msgTemplateEncode(t *testing.T) {
  35. convey.Convey("msgTemplateDesc编码", t, func() {
  36. for _, g := range d.FanGroups {
  37. ascii := strconv.QuoteToASCII(g.MsgTemplateDesc)
  38. msgtemp := hex.EncodeToString([]byte(ascii))
  39. t.Logf("the group(%s) msgtemplate encoded(%v)\n", g.Name, msgtemp)
  40. ascii = strconv.QuoteToASCII(g.MsgTemplate)
  41. msgtemp2 := hex.EncodeToString([]byte(ascii))
  42. convey.So(msgtemp, convey.ShouldEqual, msgtemp2)
  43. }
  44. })
  45. }
  46. func Test_msgTemplateDecode(t *testing.T) {
  47. convey.Convey("msgTemplateDesc解码", t, func() {
  48. for _, g := range d.FanGroups {
  49. convey.So(g.MsgTemplate, convey.ShouldEqual, g.MsgTemplateDesc)
  50. }
  51. })
  52. }
  53. func Test_keyname(t *testing.T) {
  54. convey.Convey("fangroup keyname", t, func() {
  55. for gkey, g := range d.FanGroups {
  56. convey.So(gkey, convey.ShouldEqual, fanGroupKey(g.RelationType, g.Name))
  57. }
  58. })
  59. }
  60. func Test_conf(t *testing.T) {
  61. convey.Convey("配置结果", t, func() {
  62. for gkey, g := range d.FanGroups {
  63. convey.So(gkey, convey.ShouldEqual, fanGroupKey(g.RelationType, g.Name))
  64. convey.So(len(strings.Split(g.MsgTemplateDesc, "\r\n")), convey.ShouldEqual, 2)
  65. convey.So(g.MsgTemplate, convey.ShouldEqual, g.MsgTemplateDesc)
  66. }
  67. for i, g := range d.Proportions {
  68. proportion, _ := strconv.ParseFloat(d.c.ArcPush.Proportions[i].Proportion, 64)
  69. convey.So(g.MaxValue-g.MinValue+1, convey.ShouldEqual, proportion*100)
  70. }
  71. convey.So(len(d.GroupOrder), convey.ShouldEqual, len(d.c.ArcPush.Order))
  72. })
  73. }