bws_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package bws
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "go-common/app/interface/main/activity/conf"
  8. "go-common/app/interface/main/activity/model/bws"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var d *Dao
  12. func WithDao(f func(d *Dao)) func() {
  13. return func() {
  14. dir, _ := filepath.Abs("../../cmd/activity-test.toml")
  15. flag.Set("conf", dir)
  16. if err := conf.Init(); err != nil {
  17. panic(err)
  18. }
  19. if d == nil {
  20. d = New(conf.Conf)
  21. }
  22. f(d)
  23. }
  24. }
  25. func TestDao_Binding(t *testing.T) {
  26. Convey("test binding", t, WithDao(func(d *Dao) {
  27. key := "9875fa517967622b"
  28. err := d.Binding(context.Background(), 908087, &bws.ParamBinding{Key: key})
  29. So(err, ShouldBeNil)
  30. }))
  31. }
  32. func TestDao_UsersKey(t *testing.T) {
  33. Convey("test users key", t, WithDao(func(d *Dao) {
  34. key := "9875fa517967622b"
  35. data, err := d.UsersKey(context.Background(), key)
  36. So(err, ShouldBeNil)
  37. Printf("%+v", data)
  38. }))
  39. }
  40. func TestDao_UsersMid(t *testing.T) {
  41. Convey("test users mid", t, WithDao(func(d *Dao) {
  42. mid := int64(908087)
  43. data, err := d.UsersMid(context.Background(), mid)
  44. So(err, ShouldBeNil)
  45. Printf("%+v", data)
  46. }))
  47. }
  48. func TestDao_CacheUsersMid(t *testing.T) {
  49. Convey("test cache users mid", t, WithDao(func(d *Dao) {
  50. mid := int64(908087)
  51. data, err := d.CacheUsersMid(context.Background(), mid)
  52. So(err, ShouldBeNil)
  53. Printf("%+v", data)
  54. }))
  55. }
  56. func TestDao_DelCacheUsersMid(t *testing.T) {
  57. Convey("test delete users mid", t, WithDao(func(d *Dao) {
  58. mid := int64(908087)
  59. err := d.DelCacheUsersMid(context.Background(), mid)
  60. So(err, ShouldBeNil)
  61. }))
  62. }
  63. func TestDao_RawUsersKey(t *testing.T) {
  64. Convey("test users mid", t, WithDao(func(d *Dao) {
  65. keyID := int64(1)
  66. data, err := d.UserByID(context.Background(), keyID)
  67. So(err, ShouldBeNil)
  68. Printf("%+v", data)
  69. }))
  70. }