service_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/report-click/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var svr *Service
  12. func init() {
  13. flag.Parse()
  14. dir, _ := filepath.Abs("../cmd/report-click.toml")
  15. flag.Set("conf", dir)
  16. conf.Init()
  17. svr = New(conf.Conf)
  18. }
  19. func TestReport(t *testing.T) {
  20. var (
  21. c = context.Background()
  22. err error
  23. aid = "11159485"
  24. cid = "18464413"
  25. mid = "35152246"
  26. playedTime = "0"
  27. realtime = "0"
  28. tp = "3"
  29. dt = "2"
  30. bs = []byte("this is test massage ")
  31. )
  32. Convey("Decrypt Verify err should return nil", t, func() {
  33. bs, _ = svr.Decrypt(bs, conf.Conf.Click.AesKey, conf.Conf.Click.AesIv)
  34. svr.Verify(bs, conf.Conf.Click.AesSalt, time.Now())
  35. })
  36. Convey("Report err should return nil", t, func() {
  37. err = svr.Report(c, playedTime, cid, tp, "", realtime, aid, mid, "", "", dt, "1516695880")
  38. So(err, ShouldBeNil)
  39. })
  40. Convey("CheckDid err should return nil", t, func() {
  41. svr.CheckDid("1516695880")
  42. })
  43. Convey("GenDid err should return nil", t, func() {
  44. svr.GenDid("127.0.0.1", time.Now())
  45. })
  46. Convey("Play err should return nil", t, func() {
  47. svr.Play(c, "web", "128546345", "12345", "", "14771787", "1", "", "", "", "127.0.0.1", "2", "1", "1212", "", "1", "3", "2", "4", "", "", "", "", "", "")
  48. })
  49. }