ugc_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package ugc
  2. import (
  3. "flag"
  4. "path/filepath"
  5. "testing"
  6. "time"
  7. "encoding/json"
  8. "go-common/app/job/main/tv/conf"
  9. "go-common/app/job/main/tv/model/ugc"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. srv *Service
  14. )
  15. func init() {
  16. dir, _ := filepath.Abs("../../cmd/tv-job-test.toml")
  17. flag.Set("conf", dir)
  18. conf.Init()
  19. srv = New(conf.Conf)
  20. time.Sleep(time.Second)
  21. }
  22. func WithService(f func(s *Service)) func() {
  23. return func() {
  24. f(srv)
  25. }
  26. }
  27. func TestService_ArcHandle(t *testing.T) {
  28. Convey("TestService_ArcHandle", t, WithService(func(s *Service) {
  29. msg := []byte(`{"action":"update","table":"archive","new":{"id":0,"aid":10110186,"mid":27515615,"typeid":76,"videos":1,"title":"xxx","cover":"http://i0.hdslb.com/bfs/archive/b5beb958f94f5deb6d3ba8775c4e81d2cf0f4bc1.jpg","content":"万年不变小电视","duration":10,"attribute":2113536,"copyright":1,"access":0,"pubtime":"2018-06-12 19:40:23","ctime":"2018-06-12 19:40:28","mtime":"",
  30. "state":0,"mission_id":0,"order_id":0,"redirect_url":"","forward":0,"dynamic":""},"old":{"id":0,"aid":10110186,"mid":27515615,"typeid":76,"videos":1,"title":"XXXX","cover":"http://i0.hdslb.com/bfs/archive/b5beb958f94f5deb6d3ba8775c4e81d2cf0f4bc1.jpg","content":"万年不变小电视","duration":10,"attribute":2113536,"copyright":1,"access":0,"pubtime":"2018-06-12 19:40:23","ctime":"2018-06-12 19:40:28","mtime":"",
  31. "state":0,"mission_id":0,"order_id":0,"redirect_url":"","forward":0,"dynamic":""}}`)
  32. var ms = &ugc.ArcMsg{}
  33. err := json.Unmarshal(msg, ms)
  34. s.ArcHandle(ms)
  35. So(err, ShouldBeNil)
  36. }))
  37. }