hbase_pwd_log_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "reflect"
  6. "testing"
  7. "go-common/app/job/main/passport/model"
  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 TestDao_AddPwdLogHBase(t *testing.T) {
  14. convey.Convey("AddPwdLogHBase", t, func(ctx convey.C) {
  15. var (
  16. c = context.Background()
  17. a = &model.PwdLog{}
  18. )
  19. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  20. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.pwdLogHBase), "PutStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ map[string]map[string][]byte, _ ...func(hrpc.Call) error) (res *hrpc.Result, err error) {
  21. return nil, nil
  22. })
  23. defer mock.Unpatch()
  24. err := d.AddPwdLogHBase(c, a)
  25. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  26. ctx.So(err, convey.ShouldBeNil)
  27. })
  28. })
  29. ctx.Convey("When error", func(ctx convey.C) {
  30. mock := monkey.PatchInstanceMethod(reflect.TypeOf(d.pwdLogHBase), "PutStr", func(_ *hbase.Client, _ context.Context, _, _ string, _ map[string]map[string][]byte, _ ...func(hrpc.Call) error) (res *hrpc.Result, err error) {
  31. return nil, fmt.Errorf("error")
  32. })
  33. defer mock.Unpatch()
  34. err := d.AddPwdLogHBase(c, a)
  35. ctx.Convey("Then err should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDao_rowKeyPwdLog(t *testing.T) {
  42. convey.Convey("rowKeyPwdLog", t, func() {
  43. res := rowKeyPwdLog(0, 0)
  44. convey.So(res, convey.ShouldNotBeNil)
  45. })
  46. }