notice_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/admin/main/reply/model"
  7. xtime "go-common/library/time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var nowTs = time.Now().Unix()
  11. func Test_OnlineNoticeConflict(t *testing.T) {
  12. c := context.Background()
  13. nt := model.Notice{
  14. Plat: model.PlatAndroid,
  15. Condition: model.ConditionGT,
  16. Build: 1113,
  17. Title: "测试",
  18. Status: model.StatusOffline,
  19. Content: "测试内容",
  20. Link: "http://www.bilibili.com",
  21. StartTime: xtime.Time(nowTs),
  22. EndTime: xtime.Time(nowTs + 10*3600),
  23. ClientType: "",
  24. }
  25. nt2 := model.Notice{
  26. Plat: model.PlatAndroid,
  27. Condition: model.ConditionGT,
  28. Build: 1000,
  29. Title: "测试2",
  30. Status: model.StatusOffline,
  31. Content: "测试内容2",
  32. Link: "http://www.bilibili.com",
  33. StartTime: xtime.Time(nowTs - 5*3600),
  34. EndTime: xtime.Time(nowTs + 5*3600),
  35. ClientType: "android",
  36. }
  37. Convey("test notice data conflict ", t, WithService(func(s *Service) {
  38. id1, err := s.CreateNotice(c, &nt)
  39. So(err, ShouldBeNil)
  40. id2, err := s.CreateNotice(c, &nt2)
  41. So(err, ShouldBeNil)
  42. defer func() {
  43. s.DeleteNotice(c, uint32(id1))
  44. s.DeleteNotice(c, uint32(id2))
  45. }()
  46. err = s.UpdateNoticeStatus(c, model.StatusOnline, uint32(id1))
  47. So(err, ShouldBeNil)
  48. err = s.UpdateNoticeStatus(c, model.StatusOnline, uint32(id2))
  49. So(err, ShouldNotBeNil)
  50. }))
  51. }