mc_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/ep/saga/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoPingMC(t *testing.T) {
  9. convey.Convey("pingMC", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. )
  13. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  14. err := d.pingMC(c)
  15. ctx.Convey("The err should be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestMcData(t *testing.T) {
  22. convey.Convey("test mc data", t, func(ctx convey.C) {
  23. var (
  24. c = context.Background()
  25. key = "111"
  26. dataSet = make(map[string]*model.TeamDataResp)
  27. dataGet = make(map[string]*model.TeamDataResp)
  28. )
  29. teamData := &model.TeamDataResp{
  30. Department: "live",
  31. Business: "ios",
  32. QueryDes: "description",
  33. Total: 10,
  34. }
  35. dataSet["zhangsan"] = teamData
  36. ctx.Convey("set data", func(ctx convey.C) {
  37. err := d.SetData(c, key, dataSet)
  38. ctx.Convey("set err should be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. })
  42. ctx.Convey("get data", func(ctx convey.C) {
  43. err := d.GetData(c, key, &dataGet)
  44. _, ok := dataGet["zhangsan"]
  45. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  46. ctx.So(err, convey.ShouldBeNil)
  47. ctx.So(ok, convey.ShouldEqual, true)
  48. ctx.So(dataGet["zhangsan"].Department, convey.ShouldEqual, "live")
  49. ctx.So(dataGet["zhangsan"].Total, convey.ShouldEqual, 10)
  50. })
  51. })
  52. ctx.Convey("delete data", func(ctx convey.C) {
  53. err := d.DeleteData(c, key)
  54. _, ok := dataGet["zhangsan"]
  55. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(ok, convey.ShouldEqual, false)
  58. })
  59. })
  60. })
  61. }
  62. func TestMcPipeline(t *testing.T) {
  63. convey.Convey("test mc Pipeline", t, func(ctx convey.C) {
  64. var (
  65. c = context.Background()
  66. key = "111"
  67. )
  68. pipelineData := &model.PipelineDataResp{
  69. Department: "openplatform",
  70. Business: "android",
  71. QueryDes: "description",
  72. Total: 11,
  73. }
  74. ctx.Convey("set pipeline data", func(ctx convey.C) {
  75. err := d.SetPipeline(c, key, pipelineData)
  76. ctx.Convey("set err should be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. ctx.Convey("get pipeline data", func(ctx convey.C) {
  81. pipeline, err := d.GetPipeline(c, key)
  82. ctx.Convey("get err should be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(pipeline.Business, convey.ShouldEqual, "android")
  85. ctx.So(pipeline.Total, convey.ShouldEqual, 11)
  86. })
  87. })
  88. })
  89. }