hbase_set2_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package data
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. "github.com/bouk/monkey"
  7. "github.com/tsuna/gohbase/hrpc"
  8. "go-common/app/admin/main/up/model/datamodel"
  9. hbase "go-common/library/database/hbase.v2"
  10. "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestDataUpArchiveInfo(t *testing.T) {
  13. convey.Convey("UpArchiveInfo", t, func(ctx convey.C) {
  14. var (
  15. c = context.Background()
  16. mids = []int64{}
  17. dataType UpArchiveDataType
  18. )
  19. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  20. result, err := d.UpArchiveInfo(c, mids, dataType)
  21. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldNotBeNil)
  23. ctx.So(result, convey.ShouldBeNil)
  24. })
  25. })
  26. })
  27. }
  28. func TestDataUpArchiveTagInfo(t *testing.T) {
  29. convey.Convey("UpArchiveTagInfo", t, func(ctx convey.C) {
  30. var (
  31. c = context.Background()
  32. mid = int64(0)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. result, err := d.UpArchiveTagInfo(c, mid)
  36. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  37. ctx.So(err, convey.ShouldNotBeNil)
  38. ctx.So(result, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDataUpArchiveTypeInfo(t *testing.T) {
  44. convey.Convey("UpArchiveTypeInfo", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. mid = int64(0)
  48. )
  49. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  50. result, err := d.UpArchiveTypeInfo(c, mid)
  51. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldNotBeNil)
  53. ctx.So(result, convey.ShouldNotBeNil)
  54. })
  55. })
  56. })
  57. }
  58. func TestDatagetHbaseRowResult(t *testing.T) {
  59. convey.Convey("getHbaseRowResult", t, func(ctx convey.C) {
  60. var (
  61. c = context.Background()
  62. table = "crm"
  63. key = "123"
  64. result = datamodel.UpArchiveTypeData{}
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "GetStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  68. res := &hrpc.Result{}
  69. return res, nil
  70. })
  71. defer guard.Unpatch()
  72. err := d.getHbaseRowResult(c, table, key, &result)
  73. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  74. ctx.So(err, convey.ShouldBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestDatagenerateTableName(t *testing.T) {
  80. convey.Convey("generateTableName", t, func(ctx convey.C) {
  81. var (
  82. prefix = ""
  83. date = ""
  84. )
  85. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  86. p1 := generateTableName(prefix, date)
  87. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  88. ctx.So(p1, convey.ShouldNotBeNil)
  89. })
  90. })
  91. })
  92. }