extra_func_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. . "github.com/smartystreets/goconvey/convey"
  6. "go-common/app/admin/main/videoup/conf"
  7. "testing"
  8. )
  9. func TestTypeTopParent(t *testing.T) {
  10. err := conf.Init()
  11. if err != nil {
  12. return
  13. }
  14. s := New(conf.Conf)
  15. Convey("test TypeTopParent", t, func() {
  16. _, err := s.TypeTopParent(int16(1808))
  17. So(err, ShouldNotBeNil)
  18. })
  19. }
  20. // TestArchiveRound 测试商单稿件round
  21. func TestPorderArchiveRound(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. aid int64 = 5464730 //稿件id
  25. mid int64 = 254386 //up主id
  26. typeID int16 = 22 //分区id
  27. nowRound int8 = 10 //二审提交
  28. newState int8 = -40 //定时发布
  29. resRound = 21 //最终返回的round结果
  30. )
  31. err := conf.Init()
  32. if err != nil {
  33. return
  34. }
  35. s := New(conf.Conf)
  36. Convey("test TestPorderArchiveRound", t, func() {
  37. round := s.archiveRound(c, nil, aid, mid, typeID, nowRound, newState, false)
  38. //round == 21
  39. So(round, ShouldEqual, resRound)
  40. })
  41. }
  42. func TestStringHandler(t *testing.T) {
  43. var res string
  44. delimiter := ","
  45. s1 := "t1,t2"
  46. s2 := "t1"
  47. s3 := "t2"
  48. s4 := "t3"
  49. s5 := "t1,t2,t3"
  50. s6 := "t1,t3,t4,t5"
  51. s7 := "t1,t2,t3,t4,t5"
  52. Convey("StringHandler", t, func() {
  53. //增删空字符串
  54. res = StringHandler(s1, "", delimiter, false)
  55. So(res, ShouldEqual, s1)
  56. res = StringHandler(s1, "", delimiter, true)
  57. So(res, ShouldEqual, s1)
  58. //增删重复字符串
  59. res = StringHandler(s1, s2, delimiter, false)
  60. So(res, ShouldEqual, s1)
  61. res = StringHandler(s1, s2, delimiter, true)
  62. So(res, ShouldEqual, s3)
  63. //增删不重复字符串
  64. res = StringHandler(s1, s4, delimiter, false)
  65. So(res, ShouldEqual, s5)
  66. res = StringHandler(s1, s4, delimiter, true)
  67. So(res, ShouldEqual, s1)
  68. //增删多个重复,且多个不重复字符串
  69. res = StringHandler(s5, s6, delimiter, false)
  70. So(res, ShouldEqual, s7)
  71. res = StringHandler(s5, s6, delimiter, true)
  72. So(res, ShouldEqual, s3)
  73. })
  74. }
  75. // TestSplitInts
  76. func TestSplitInts(t *testing.T) {
  77. var (
  78. str = " 123,334343\n,\t1\r11"
  79. )
  80. err := conf.Init()
  81. if err != nil {
  82. return
  83. }
  84. s := New(conf.Conf)
  85. Convey("test TestSplitInts", t, func() {
  86. ids, err := s.SplitInts(str)
  87. fmt.Print(ids)
  88. So(ids, ShouldNotBeNil)
  89. So(err, ShouldBeNil)
  90. })
  91. }