dao_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package lic
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "go-common/app/job/main/tv/conf"
  8. "fmt"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. ctx = context.Background()
  13. d *Dao
  14. xmlBody = `inputTime=20180606&sign=timer-import_BILIBILI&tId=UHZFmufgweRpWhqAzToFYMWtYuZhMKCU&xmlData=<?xmlversion="1.0"encoding="UTF-8"?><Serviceid="dataSync"><Head><TradeId>UHZFmufgweRpWhqAzToFYMWtYuZhMKCU</TradeId><Date>2018-06-06</Date><Count>1</Count></Head><Body><programSetList><programSet><programSetId>ugc10100044</programSetId><programSetName>drm</programSetName><programSetClass></programSetClass><programSetType></programSetType><programSetPoster>http://i1.hdslb.com/bfs/archive/diuren.png</programSetPoster><publishDate>2018-01-30</publishDate><copyright>bilibili</copyright><programCount>1</programCount><cREndDate>1970-01-01</cREndDate><definitionType>SD</definitionType><cpCode>BILIBILI</cpCode><payStatus>0</payStatus><primitiveName></primitiveName><alias></alias><zone></zone><leadingRole></leadingRole><programSetDesc>drm</programSetDesc><Staff></Staff><programList><program><programId>ugc10114149</programId><programName>1</programName><programPoster></programPoster><programLength>1448</programLength><publishDate>1970-01-01</publishDate><ifPreview>0</ifPreview><number>1</number><definitionType>SD</definitionType><playCount>0</playCount><drm>0</drm><programMediaList><programMedia><mediaId>ugc10114149</mediaId><playUrl>http://upos-hz-tvshenhe.acgvideo.com/upgcxcode/87/75/41057587/41057587-1-6.mp4</playUrl><definition>SD</definition><htmlUrl>http://upos-hz-tvshenhe.acgvideo.com/upgcxcode/87/75/41057587/41057587-1-6.mp4</htmlUrl></programMedia></programMediaList></program></programList></programSet></programSetList></Body></Service>`
  15. )
  16. func WithDao(f func(d *Dao)) func() {
  17. return func() {
  18. dir, _ := filepath.Abs("../../cmd/tv-job-test.toml")
  19. flag.Set("conf", dir)
  20. conf.Init()
  21. if d == nil {
  22. d = New(conf.Conf)
  23. }
  24. f(d)
  25. }
  26. }
  27. func TestDelEpLic(t *testing.T) {
  28. Convey("TestDao_CallRetry", t, WithDao(func(d *Dao) {
  29. res := DelEpLic("ugc", "timer-import_BILIBILI", []int{10109083, 10109084})
  30. So(len(res), ShouldBeGreaterThan, 0)
  31. fmt.Println(res)
  32. }))
  33. }
  34. func TestDao_CallRetry(t *testing.T) {
  35. Convey("TestDao_CallRetry", t, WithDao(func(d *Dao) {
  36. res, err := d.CallRetry(ctx, d.conf.Sync.API.AddURL, xmlBody)
  37. So(err, ShouldBeNil)
  38. So(res, ShouldNotBeNil)
  39. }))
  40. }
  41. func TestDao_CallLic(t *testing.T) {
  42. Convey("TestDao_CallLic", t, WithDao(func(d *Dao) {
  43. result, err := d.callLic(ctx, d.conf.Sync.API.AddURL, xmlBody)
  44. So(err, ShouldBeNil)
  45. So(result, ShouldNotBeNil)
  46. }))
  47. }