mysql_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/answer/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoIDsByState(t *testing.T) {
  11. Convey("IDsByState", t, func() {
  12. _, err := d.IDsByState(context.TODO())
  13. So(err, ShouldBeNil)
  14. })
  15. }
  16. func TestDaoQuestionAll(t *testing.T) {
  17. var id int64 = 1
  18. q := &model.QuestionDB{ID: id, State: 1}
  19. Convey("QuestionAdd", t, func() {
  20. aff, err := d.QuestionAdd(context.TODO(), q)
  21. So(err, ShouldBeNil)
  22. So(aff, ShouldNotBeNil)
  23. })
  24. Convey("QueByID", t, func() {
  25. que, err := d.QueByID(context.TODO(), id)
  26. So(err, ShouldBeNil)
  27. So(que, ShouldNotBeNil)
  28. })
  29. Convey("QuestionEdit", t, func() {
  30. q.Question = "testone"
  31. aff, err := d.QuestionEdit(context.TODO(), q)
  32. So(err, ShouldBeNil)
  33. So(aff, ShouldNotBeNil)
  34. })
  35. Convey("ByIDs", t, func() {
  36. res, err := d.ByIDs(context.TODO(), []int64{id})
  37. So(err, ShouldBeNil)
  38. So(res, ShouldNotBeNil)
  39. })
  40. }
  41. func TestDaoQuestionPage(t *testing.T) {
  42. arg := &model.ArgQue{State: 1}
  43. Convey("QuestionList", t, func() {
  44. res, err := d.QuestionList(context.TODO(), arg)
  45. So(err, ShouldBeNil)
  46. So(res, ShouldNotBeNil)
  47. })
  48. Convey("QuestionCount", t, func() {
  49. res, err := d.QuestionCount(context.TODO(), arg)
  50. So(err, ShouldBeNil)
  51. So(res, ShouldNotBeNil)
  52. })
  53. }
  54. func TestDaoUpdateStatus(t *testing.T) {
  55. Convey("UpdateStatus", t, func() {
  56. aff, err := d.UpdateStatus(context.TODO(), 0, 0, "")
  57. So(err, ShouldBeNil)
  58. So(aff, ShouldNotBeNil)
  59. })
  60. }
  61. func TestDaoTypes(t *testing.T) {
  62. Convey("Types", t, func() {
  63. res, err := d.Types(context.TODO())
  64. So(err, ShouldBeNil)
  65. So(res, ShouldNotBeNil)
  66. })
  67. }
  68. func TestDaoTypeAdd(t *testing.T) {
  69. Convey("Types", t, func() {
  70. var allType = []*model.TypeInfo{
  71. {ID: 1, Parentid: 0, Name: "游戏"},
  72. {ID: 2, Parentid: 0, Name: "影视"},
  73. {ID: 3, Parentid: 0, Name: "科技"},
  74. {ID: 4, Parentid: 0, Name: "动画"},
  75. {ID: 5, Parentid: 0, Name: "艺术"},
  76. {ID: 6, Parentid: 0, Name: "流行前线"},
  77. {ID: 7, Parentid: 0, Name: "鬼畜"},
  78. {ID: 8, Parentid: 1, Name: "动作射击", LabelName: "游戏"},
  79. {ID: 9, Parentid: 1, Name: "冒险格斗", LabelName: "游戏"},
  80. {ID: 12, Parentid: 1, Name: "策略模拟 ", LabelName: "游戏"},
  81. {ID: 13, Parentid: 1, Name: "角色扮演 ", LabelName: "游戏"},
  82. {ID: 14, Parentid: 1, Name: "音乐体育 ", LabelName: "游戏"},
  83. {ID: 15, Parentid: 2, Name: "纪录片 ", LabelName: "影视"},
  84. {ID: 16, Parentid: 2, Name: "电影 ", LabelName: "影视"},
  85. {ID: 17, Parentid: 2, Name: "电视剧 ", LabelName: "影视"},
  86. {ID: 18, Parentid: 3, Name: "军事 ", LabelName: "科技"},
  87. {ID: 19, Parentid: 3, Name: "地理 ", LabelName: "科技"},
  88. {ID: 20, Parentid: 3, Name: "历史 ", LabelName: "科技"},
  89. {ID: 21, Parentid: 3, Name: "文学 ", LabelName: "科技"},
  90. {ID: 22, Parentid: 3, Name: "数学 ", LabelName: "科技"},
  91. {ID: 23, Parentid: 3, Name: "物理 ", LabelName: "科技"},
  92. {ID: 24, Parentid: 3, Name: "化学 ", LabelName: "科技"},
  93. {ID: 25, Parentid: 3, Name: "生物 ", LabelName: "科技"},
  94. {ID: 26, Parentid: 3, Name: "数码科技 ", LabelName: "科技"},
  95. {ID: 27, Parentid: 4, Name: "动画声优 ", LabelName: "动画"},
  96. {ID: 28, Parentid: 4, Name: "动漫内容 ", LabelName: "动画"},
  97. {ID: 29, Parentid: 5, Name: "ACG音乐 ", LabelName: "艺术"},
  98. {ID: 30, Parentid: 5, Name: "三次元音乐 ", LabelName: "艺术"},
  99. {ID: 31, Parentid: 5, Name: "绘画 ", LabelName: "艺术"},
  100. {ID: 32, Parentid: 6, Name: "娱乐 ", LabelName: "流行前线"},
  101. {ID: 33, Parentid: 6, Name: "时尚 ", LabelName: "流行前线"},
  102. {ID: 34, Parentid: 6, Name: "运动 ", LabelName: "流行前线"},
  103. {ID: 35, Parentid: 7, Name: "鬼畜 ", LabelName: "鬼畜"},
  104. {ID: 36, Parentid: 0, Name: "基础题", LabelName: "基础题"},
  105. }
  106. for _, v := range allType {
  107. res, err := d.TypeSave(context.TODO(), v)
  108. So(err, ShouldBeNil)
  109. So(res, ShouldNotBeNil)
  110. }
  111. })
  112. }
  113. func TestDaoBaseQS(t *testing.T) {
  114. Convey("TestBaseQS", t, func() {
  115. res, err := d.BaseQS(context.Background())
  116. for k, re := range res {
  117. fmt.Printf("k:%d re:%+v \n", k, re)
  118. }
  119. So(err, ShouldBeNil)
  120. So(res, ShouldNotBeNil)
  121. })
  122. }
  123. func TestDaoInsBaseQs(t *testing.T) {
  124. var qs = &model.QuestionDB{
  125. Mid: 1,
  126. IP: "127.0.0.1",
  127. Question: "qs",
  128. Ans1: "Ans1",
  129. Ans2: "Ans2",
  130. Ans3: "Ans3",
  131. Ans4: "Ans4",
  132. Tips: "tips",
  133. AvID: 1,
  134. MediaType: 1,
  135. Source: 1,
  136. Ctime: time.Now(),
  137. Mtime: time.Now(),
  138. Operator: "operator",
  139. }
  140. Convey("TestInsBaseQs", t, func() {
  141. af, err := d.InsBaseQs(context.Background(), qs)
  142. fmt.Printf("%+v \n", af)
  143. So(err, ShouldBeNil)
  144. })
  145. }
  146. func TestAllQS(t *testing.T) {
  147. Convey("TestAllQS", t, func() {
  148. res, err := d.AllQS(context.Background())
  149. for k, re := range res {
  150. fmt.Printf("k:%d re:%+v \n", k, re)
  151. }
  152. So(err, ShouldBeNil)
  153. So(res, ShouldNotBeNil)
  154. })
  155. }