resource_test.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package gorm
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/aegis/model/resource"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestGormListHelperForTask(t *testing.T) {
  9. convey.Convey("ListHelperForTask", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. rids = []int64{}
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. res, err := d.ListHelperForTask(c, rids)
  16. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. ctx.So(res, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestGormResourceByOID(t *testing.T) {
  24. var (
  25. c = context.Background()
  26. )
  27. convey.Convey("ResourceByOID", t, func(ctx convey.C) {
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. _, err := d.ResourceByOID(c, "", 0)
  30. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestGormOidByRID(t *testing.T) {
  37. var (
  38. c = context.Background()
  39. )
  40. convey.Convey("OidByRID", t, func(ctx convey.C) {
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. _, err := d.OidByRID(c, 0)
  43. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. })
  46. })
  47. })
  48. }
  49. func TestGormTxUpdateResult(t *testing.T) {
  50. convey.Convey("TxUpdateResult", t, func(ctx convey.C) {
  51. var (
  52. tx, _ = d.BeginTx(context.TODO())
  53. rid = int64(0)
  54. res = map[string]interface{}{"extra1": 1}
  55. rscRes = &resource.Result{}
  56. )
  57. defer tx.Commit()
  58. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  59. err := d.TxUpdateResult(tx, rid, res, rscRes)
  60. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. })
  65. }
  66. func TestGormResourceRes(t *testing.T) {
  67. convey.Convey("ResourceRes", t, func(ctx convey.C) {
  68. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  69. _, err := d.ResourceRes(context.TODO(), 0)
  70. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  71. ctx.So(err, convey.ShouldBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestGormResByOID(t *testing.T) {
  77. convey.Convey("ResByOID", t, func(ctx convey.C) {
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. _, err := d.ResByOID(context.TODO(), 0, "")
  80. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. })
  85. }
  86. func TestGormUpdateResource(t *testing.T) {
  87. convey.Convey("UpdateResource", t, func(ctx convey.C) {
  88. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  89. d.UpdateResource(context.TODO(), 1, "xyz", map[string]interface{}{"mid": 123})
  90. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  91. })
  92. })
  93. })
  94. }
  95. func TestGormResOIDByID(t *testing.T) {
  96. convey.Convey("ResOIDByID", t, func(ctx convey.C) {
  97. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  98. res, err := d.ResOIDByID(context.TODO(), []int64{1, 2})
  99. t.Logf("res(%+v)", res)
  100. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  101. convey.So(err, convey.ShouldBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestGormResIDByOID(t *testing.T) {
  107. convey.Convey("ResIDByOID", t, func(ctx convey.C) {
  108. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  109. res, err := d.ResIDByOID(context.TODO(), 1, []string{"1", "2"})
  110. t.Logf("res(%+v)", res)
  111. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  112. convey.So(err, convey.ShouldBeNil)
  113. })
  114. })
  115. })
  116. }
  117. func TestGormResourceHit(t *testing.T) {
  118. convey.Convey("ResourceHit", t, func(ctx convey.C) {
  119. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  120. _, err := d.ResourceHit(context.TODO(), []int64{})
  121. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  122. convey.So(err, convey.ShouldBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestGormResultByRID(t *testing.T) {
  128. convey.Convey("ResultByRID", t, func(ctx convey.C) {
  129. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  130. d.ResultByRID(context.TODO(), 50)
  131. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  132. })
  133. })
  134. })
  135. }
  136. func TestGormRidsByOids(t *testing.T) {
  137. convey.Convey("RidsByOids", t, func(ctx convey.C) {
  138. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  139. d.RidsByOids(cntx, 0, []string{})
  140. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  141. })
  142. })
  143. })
  144. }
  145. func TestGormTxUpdateResource(t *testing.T) {
  146. convey.Convey("TxUpdateResource", t, func(ctx convey.C) {
  147. var (
  148. tx, _ = d.BeginTx(context.TODO())
  149. rid = int64(0)
  150. res = map[string]interface{}{"extra1": 1}
  151. )
  152. defer tx.Commit()
  153. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  154. err := d.TxUpdateResource(tx, rid, res)
  155. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  156. ctx.So(err, convey.ShouldBeNil)
  157. })
  158. })
  159. })
  160. }
  161. func TestGormTxUpdateState(t *testing.T) {
  162. convey.Convey("TxUpdateState", t, func(ctx convey.C) {
  163. var (
  164. tx, _ = d.BeginTx(context.TODO())
  165. rids = []int64{0}
  166. )
  167. defer tx.Commit()
  168. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  169. err := d.TxUpdateState(tx, rids, 0)
  170. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  171. ctx.So(err, convey.ShouldBeNil)
  172. })
  173. })
  174. })
  175. }
  176. func TestGormMetaByRID(t *testing.T) {
  177. convey.Convey("MetaByRID", t, func(ctx convey.C) {
  178. var (
  179. rids = []int64{0}
  180. )
  181. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  182. _, err := d.MetaByRID(cntx, rids)
  183. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  184. ctx.So(err, convey.ShouldBeNil)
  185. })
  186. })
  187. })
  188. }
  189. func TestGormUpsertByOIDs(t *testing.T) {
  190. convey.Convey("UpsertByOIDs", t, func(ctx convey.C) {
  191. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  192. res, err := d.UpsertByOIDs(context.TODO(), 1, []string{"oid000001", "oid000002"})
  193. for _, item := range res {
  194. t.Logf("res(%+v)", item)
  195. }
  196. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  197. ctx.So(err, convey.ShouldBeNil)
  198. })
  199. })
  200. })
  201. }