model_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package model
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestFuncs(t *testing.T) {
  8. Convey("int string functions", t, func() {
  9. Convey("SplitInts", func() {
  10. res := SplitInts("1,2,3")
  11. So(res, ShouldResemble, []int{1, 2, 3})
  12. })
  13. Convey("JoinInts", func() {
  14. ints := []int{1, 2, 3}
  15. res := JoinInts(ints)
  16. So(res, ShouldEqual, "1,2,3")
  17. })
  18. Convey("existsInt", func() {
  19. exists := ExistsInt([]int{}, 4)
  20. So(exists, ShouldBeFalse)
  21. ints := []int{1, 2, 3}
  22. exists = ExistsInt(ints, 1)
  23. So(exists, ShouldBeTrue)
  24. exists = ExistsInt(ints, 4)
  25. So(exists, ShouldBeFalse)
  26. })
  27. Convey("gen temp task id", func() {
  28. id := TempTaskID()
  29. So(len(id), ShouldEqual, 9)
  30. })
  31. Convey("gen job name", func() {
  32. name := JobName(time.Now().UnixNano(), "123", "456", "g")
  33. t.Logf("job name is: %d", name)
  34. })
  35. })
  36. Convey("ParseBuild", t, func() {
  37. buildString := `{"2":{"Build":100,"Condition":"gt"}}`
  38. build := ParseBuild(buildString)
  39. So(build, ShouldResemble, map[int]*Build{2: {Build: 100, Condition: "gt"}})
  40. })
  41. Convey("platform", t, func() {
  42. plat := Platform("iphone", PushSDKApns)
  43. So(plat, ShouldEqual, PlatformIPhone)
  44. plat = Platform("ipad", PushSDKApns)
  45. So(plat, ShouldEqual, PlatformIPad)
  46. plat = Platform("whatever", PushSDKXiaomi)
  47. So(plat, ShouldEqual, PlatformXiaomi)
  48. })
  49. Convey("parse silent time", t, func() {
  50. st := ParseSilentTime("22:30-06:00")
  51. So(st, ShouldResemble, BusinessSilentTime{
  52. BeginHour: 22,
  53. EndHour: 6,
  54. BeginMinute: 30,
  55. EndMinute: 0,
  56. })
  57. })
  58. }
  59. func TestValidateBuild(t *testing.T) {
  60. builds := map[int]*Build{
  61. 1: {Build: 520000, Condition: "eq"},
  62. 2: {Build: 123456, Condition: "gt"},
  63. }
  64. Convey("ValidateBuild", t, func() {
  65. b := ValidateBuild(2, 123455, builds)
  66. So(b, ShouldBeFalse)
  67. b = ValidateBuild(2, 123457, builds)
  68. So(b, ShouldBeTrue)
  69. b = ValidateBuild(4, 520001, builds)
  70. So(b, ShouldBeFalse)
  71. b = ValidateBuild(4, 519999, builds)
  72. So(b, ShouldBeFalse)
  73. b = ValidateBuild(4, 520000, builds)
  74. So(b, ShouldBeTrue)
  75. })
  76. }
  77. func TestScheme(t *testing.T) {
  78. Convey("Scheme()", t, func() {
  79. scheme := Scheme(LinkTypeLive, "1,0", PlatformAndroid, 5300000)
  80. So(scheme, ShouldEqual, "bilibili://live/1?broadcast_type=0")
  81. scheme = Scheme(LinkTypeLive, "1", PlatformAndroid, 5280000)
  82. So(scheme, ShouldEqual, "bili:///?type=bililive&roomid=1")
  83. scheme = Scheme(LinkTypeLive, "1,1", PlatformIPhone, 5300000)
  84. So(scheme, ShouldEqual, "bilibili://live/1?broadcast_type=1")
  85. scheme = Scheme(LinkTypeLive, "1,0", PlatformIPhone, 5280000)
  86. So(scheme, ShouldEqual, "bilibili://live/1?broadcast_type=0")
  87. scheme = Scheme(LinkTypeCustom, "custom_scheme", PlatformIPhone, 68)
  88. So(scheme, ShouldEqual, "custom_scheme")
  89. })
  90. }