archive_test.go 759 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/binary"
  6. "io"
  7. "testing"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDao_PvData(t *testing.T) {
  11. convey.Convey("test pvdata", t, func(ctx convey.C) {
  12. url := "http://i3.hdslb.com/bfs/videoshot/10135146.bin?vsign=5d5c80b9c583b1ce49f0fb8ab8dd178568efa66c&ver=108653418"
  13. res, err := d.PvData(context.Background(), url)
  14. ctx.So(err, convey.ShouldBeNil)
  15. var (
  16. v uint16
  17. pvs []uint16
  18. buf = bytes.NewReader(res)
  19. )
  20. for {
  21. if err = binary.Read(buf, binary.BigEndian, &v); err != nil {
  22. if err != io.EOF {
  23. ctx.Printf("binary.Read err(%v)", err)
  24. }
  25. err = nil
  26. break
  27. }
  28. pvs = append(pvs, v)
  29. }
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.Printf("%+v", pvs)
  32. })
  33. }