coinstream_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package dao
  2. import (
  3. "testing"
  4. "fmt"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/service/live/wallet/model"
  7. "time"
  8. )
  9. func TestGetTable(t *testing.T) {
  10. Convey("Get Table", t, func() {
  11. once.Do(startService)
  12. t := getCoinStreamTable("89689d8c2290d93183b96c7ec83ea3c61114")
  13. So(t, ShouldEqual, "t_coin_stream_201704")
  14. t = getCoinStreamTable("31ea4d87162d3ed9c1dfb804eb960c640119")
  15. So(t, ShouldEqual, "t_coin_stream_201709")
  16. t = getCoinStreamTable("9937727a8c7fed5bbecd93642b4982561121")
  17. So(t, ShouldEqual, "t_coin_stream_201801")
  18. tid := GetTid(1, map[string]string{"a": "a", "b": "b"})
  19. t = getCoinStreamTable(tid)
  20. now := time.Now()
  21. So(t, ShouldEqual, fmt.Sprintf("t_coin_stream_%d%02d", now.Year(), int(now.Month())))
  22. })
  23. }
  24. func TestDao_NewCoinStreamRecord(t *testing.T) {
  25. Convey("new coin stream", t, func() {
  26. once.Do(startService)
  27. r := model.CoinStreamRecord{
  28. Uid: 1,
  29. TransactionId: GetTid(1, map[string]string{"a": "a", "b": "b"}),
  30. ExtendTid: "abcdef",
  31. DeltaCoinNum: 1,
  32. CoinType: 0,
  33. OrgCoinNum: 100,
  34. OpResult: 2,
  35. OpReason: 0,
  36. OpType: 1,
  37. OpTime: time.Now().Unix(),
  38. BizCode: "wtf",
  39. Area: 0,
  40. Source: "",
  41. MetaData: "",
  42. BizSource: "",
  43. }
  44. affect, err := d.NewCoinStreamRecord(ctx, &r)
  45. So(err, ShouldBeNil)
  46. So(affect, ShouldEqual, 1)
  47. })
  48. }