article_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package model
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestCleanURL(t *testing.T) {
  7. Convey("different urls", t, func() {
  8. url := "/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
  9. So(CleanURL("http://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  10. So(CleanURL("https://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  11. So(CleanURL("//i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  12. So(CleanURL("http://uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  13. So(CleanURL("https://uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  14. So(CleanURL("//uat-i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"), ShouldEqual, url)
  15. })
  16. }
  17. func TestCompleteURL(t *testing.T) {
  18. Convey("prefix http", t, func() {
  19. url := "http://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
  20. So(CompleteURL(url), ShouldEqual, url)
  21. })
  22. Convey("prefix https", t, func() {
  23. url := "https://i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
  24. So(CompleteURL(url), ShouldEqual, url)
  25. })
  26. Convey("prefix //", t, func() {
  27. url := "//i0.hdslb.com/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
  28. So(CompleteURL(url), ShouldEqual, url)
  29. })
  30. Convey("prefix no prefix", t, func() {
  31. url := "/bfs/article/3b8b57821a94af4c171218a01d9cee44dc0dccf8.jpg"
  32. So(CompleteURL(url), ShouldEqual, "https://i0.hdslb.com"+url)
  33. })
  34. }
  35. func TestNoticeState(t *testing.T) {
  36. Convey("ToInt64", t, func() {
  37. a := NoticeState{"lead": true, "new": true}
  38. So(a.ToInt64(), ShouldEqual, 3)
  39. })
  40. Convey("ToInt64 2", t, func() {
  41. a := NoticeState{"lead": true, "new": false}
  42. So(a.ToInt64(), ShouldEqual, 1)
  43. })
  44. Convey("NewNoticeState", t, func() {
  45. a := NoticeState{"lead": true, "new": true}
  46. So(NewNoticeState(3), ShouldResemble, a)
  47. })
  48. Convey("NewNoticeState 2", t, func() {
  49. a := NoticeState{"lead": true, "new": false}
  50. So(NewNoticeState(1), ShouldResemble, a)
  51. })
  52. }