config_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package dao
  2. import (
  3. "context"
  4. "encoding/json"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/reply/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestAddConfig(t *testing.T) {
  11. var (
  12. c = context.Background()
  13. now = time.Now()
  14. config = &model.Config{
  15. Oid: 1,
  16. Type: 1,
  17. Category: 1,
  18. AdminID: 1,
  19. Operator: "admin",
  20. }
  21. )
  22. Convey("add a config", t, WithDao(func(d *Dao) {
  23. configValue := map[string]int64{
  24. "showentry": 0,
  25. "showadmin": 1,
  26. }
  27. bs, err := json.Marshal(configValue)
  28. So(err, ShouldBeNil)
  29. config.Config = string(bs)
  30. _, err = d.AddConfig(c, config.Type, config.Category, config.Oid, config.AdminID, config.Operator, config.Config, now)
  31. So(err, ShouldBeNil)
  32. }))
  33. }
  34. func TestLoadConfig(t *testing.T) {
  35. var (
  36. c = context.Background()
  37. config = &model.Config{
  38. Oid: 1,
  39. Type: 1,
  40. Category: 1,
  41. AdminID: 1,
  42. Operator: "admin",
  43. }
  44. )
  45. Convey("load a config", t, WithDao(func(d *Dao) {
  46. var err error
  47. config, err = d.LoadConfig(c, config.Type, config.Category, config.Oid)
  48. So(err, ShouldBeNil)
  49. So(config, ShouldNotBeNil)
  50. }))
  51. }
  52. func TestPaginateConfig(t *testing.T) {
  53. var (
  54. config = &model.Config{
  55. Oid: 1,
  56. Type: 1,
  57. Category: 1,
  58. AdminID: 1,
  59. Operator: "admin",
  60. }
  61. c = context.Background()
  62. )
  63. Convey("load a config", t, WithDao(func(d *Dao) {
  64. configs, err := d.PaginateConfig(c, config.Type, config.Category, config.Oid, config.Operator, 0, 20)
  65. So(err, ShouldBeNil)
  66. So(len(configs), ShouldNotEqual, 0)
  67. }))
  68. }
  69. func TestDeleteConfig(t *testing.T) {
  70. var (
  71. id = int64(1)
  72. c = context.Background()
  73. )
  74. Convey("load a config", t, WithDao(func(d *Dao) {
  75. _, err := d.DeleteConfig(c, id)
  76. So(err, ShouldBeNil)
  77. }))
  78. }