utils_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package data
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/library/database/hbase.v2"
  7. "github.com/smartystreets/goconvey/convey"
  8. "github.com/tsuna/gohbase/hrpc"
  9. )
  10. func TestDatagetDataWithBackup(t *testing.T) {
  11. convey.Convey("getDataWithBackup", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. client = &hbase.Client{}
  15. tableNameFunc func(retryCount int) string
  16. maxRetry = int(0)
  17. key = ""
  18. options func(hrpc.Call) error
  19. )
  20. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  21. result, err := d.getDataWithBackup(c, client, tableNameFunc, maxRetry, key, options)
  22. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. ctx.So(result, convey.ShouldBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestDatagetTableName(t *testing.T) {
  30. convey.Convey("getTableName", t, func(ctx convey.C) {
  31. var (
  32. tablePrefix = ""
  33. date = time.Now()
  34. )
  35. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  36. p1 := getTableName(tablePrefix, date)
  37. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  38. ctx.So(p1, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDatagenerateTableNameFunc(t *testing.T) {
  44. convey.Convey("generateTableNameFunc", t, func(ctx convey.C) {
  45. var (
  46. tablePrefix = ""
  47. date = time.Now()
  48. dayDiff = int(0)
  49. )
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. p1 := generateTableNameFunc(tablePrefix, date, dayDiff)
  52. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  53. ctx.So(p1, convey.ShouldNotBeNil)
  54. })
  55. })
  56. })
  57. }