relation_log_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "reflect"
  6. "testing"
  7. "time"
  8. "go-common/library/database/hbase.v2"
  9. "github.com/bouk/monkey"
  10. "github.com/smartystreets/goconvey/convey"
  11. "github.com/tsuna/gohbase/hrpc"
  12. )
  13. func TestDaoreverse(t *testing.T) {
  14. convey.Convey("reverse", t, func(convCtx convey.C) {
  15. var (
  16. s = ""
  17. )
  18. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  19. p1 := reverse(s)
  20. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  21. convCtx.So(p1, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaorpad(t *testing.T) {
  27. convey.Convey("rpad", t, func(convCtx convey.C) {
  28. var (
  29. s = ""
  30. l = int(0)
  31. )
  32. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  33. p1 := rpad(s, l)
  34. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  35. convCtx.So(p1, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaologKey(t *testing.T) {
  41. convey.Convey("logKey", t, func(convCtx convey.C) {
  42. var (
  43. mid = int64(0)
  44. fid = int64(0)
  45. ts = int64(0)
  46. )
  47. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  48. p1 := logKey(mid, fid, ts)
  49. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  50. convCtx.So(p1, convey.ShouldNotBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoRelationLogs(t *testing.T) {
  56. convey.Convey("RelationLogs", t, func(convCtx convey.C) {
  57. var (
  58. ctx = context.Background()
  59. mid = int64(0)
  60. fid = int64(0)
  61. from = time.Now()
  62. to = time.Now()
  63. )
  64. convCtx.Convey("RelationLogs failed", func(convCtx convey.C) {
  65. monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "ScanRangeStr", func(_ *hbase.Client, _ context.Context, _ string, _ string, _ string, _ ...func(hrpc.Call) error) (hrpc.Scanner, error) {
  66. return nil, fmt.Errorf("hbase scan err")
  67. })
  68. defer monkey.UnpatchAll()
  69. p1, err := d.RelationLogs(ctx, mid, fid, from, to)
  70. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  71. convCtx.So(err, convey.ShouldNotBeNil)
  72. convCtx.So(p1, convey.ShouldBeNil)
  73. })
  74. })
  75. })
  76. }