regexp_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func testRegexpDaoImplGetByCond(t *testing.T) {
  8. var (
  9. c = context.TODO()
  10. cond = &Condition{State: "0"}
  11. )
  12. convey.Convey("GetByCond", t, func(ctx convey.C) {
  13. regexps, totalCounts, err := regdi.GetByCond(c, cond)
  14. ctx.Convey("Then err should be nil.regexps,totalCounts should not be nil.", func(ctx convey.C) {
  15. ctx.So(err, convey.ShouldBeNil)
  16. ctx.So(totalCounts, convey.ShouldNotBeNil)
  17. ctx.So(regexps, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func testRegexpDaoImplDaoUpdate(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. r = &Regexp{ID: 1, Name: "name", Area: 1, Content: "test"}
  25. )
  26. convey.Convey("Update", t, func(ctx convey.C) {
  27. p1, err := regdi.Update(c, r)
  28. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. ctx.So(p1, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func testRegexpDaoImplInsert(t *testing.T) {
  35. var (
  36. c = context.TODO()
  37. r = &Regexp{ID: 1, Name: "name", Area: 1, Content: "test"}
  38. )
  39. convey.Convey("Insert", t, func(ctx convey.C) {
  40. p1, err := regdi.Insert(c, r)
  41. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func testRegexpDaoImplGetByID(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. id = int64(1)
  51. )
  52. convey.Convey("GetByID", t, func(ctx convey.C) {
  53. p1, err := regdi.GetByID(c, id)
  54. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(p1, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func testRegexpDaoImplGetByIDs(t *testing.T) {
  61. var (
  62. c = context.TODO()
  63. ids = []int64{1}
  64. )
  65. convey.Convey("RegexpDaoImplGetByIDs", t, func(ctx convey.C) {
  66. p1, err := regdi.GetByIDs(c, ids)
  67. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(p1, convey.ShouldNotBeNil)
  70. })
  71. })
  72. }
  73. func testRegexpDaoImplGetByContents(t *testing.T) {
  74. var (
  75. c = context.TODO()
  76. contents = []string{"test"}
  77. )
  78. convey.Convey("GetByContents", t, func(ctx convey.C) {
  79. p1, err := regdi.GetByContents(c, contents)
  80. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.So(p1, convey.ShouldNotBeNil)
  83. })
  84. })
  85. }
  86. func testRegexpDaoImplGetByAreaAndContent(t *testing.T) {
  87. var (
  88. c = context.TODO()
  89. cond = &Condition{State: "0"}
  90. )
  91. convey.Convey("GetByAreaAndContent", t, func(ctx convey.C) {
  92. p1, err := regdi.GetByAreaAndContent(c, cond)
  93. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(p1, convey.ShouldNotBeNil)
  96. })
  97. })
  98. }