hbase_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package data
  2. import (
  3. "context"
  4. "github.com/bouk/monkey"
  5. "github.com/tsuna/gohbase/hrpc"
  6. "go-common/library/database/hbase.v2"
  7. "reflect"
  8. "testing"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDatahbaseMd5Key(t *testing.T) {
  12. var (
  13. aid = int64(0)
  14. )
  15. convey.Convey("hbaseMd5Key", t, func(ctx convey.C) {
  16. p1 := hbaseMd5Key(aid)
  17. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  18. ctx.So(p1, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestDataBaseUpStat(t *testing.T) {
  23. var (
  24. c = context.TODO()
  25. mid = int64(0)
  26. date = ""
  27. )
  28. // Hbase never ok
  29. convey.Convey("BaseUpStat", t, func(ctx convey.C) {
  30. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.hbase), "Get", func(_ *hbase.Client, _ context.Context, _ []byte, _ []byte, _ ...func(hrpc.Call) error) (*hrpc.Result, error) {
  31. cells := make([]*hrpc.Cell, 5)
  32. for i := range cells {
  33. cell := new(hrpc.Cell)
  34. cell.Value = []byte("test")
  35. cells[i] = cell
  36. }
  37. res := &hrpc.Result{
  38. Cells: cells,
  39. }
  40. return res, nil
  41. })
  42. defer guard.Unpatch()
  43. stat, err := d.BaseUpStat(c, mid, date)
  44. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. ctx.So(stat, convey.ShouldNotBeNil)
  47. })
  48. })
  49. }