download_test.go 803 B

1234567891011121314151617181920212223242526272829
  1. package caldiff
  2. import (
  3. "bytes"
  4. "fmt"
  5. "testing"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDao_DownloadFile(t *testing.T) {
  9. var (
  10. newPath = fmt.Sprintf("%s/%s", d.c.Cfg.Diff.Folder, "123.zip")
  11. url = "http://i0.hdslb.com/bfs/face/ca14680bcfe4a956d1b6c06fbc1f6a6529257746.jpg"
  12. )
  13. Convey("TestDao_DownloadFile", t, WithDao(func(d *Dao) {
  14. httpMock("GET", url).Reply(200).Body(bytes.NewReader([]byte("test")))
  15. data, err := d.DownloadFile(ctx, url, newPath)
  16. So(err, ShouldBeNil)
  17. So(data, ShouldBeGreaterThan, 0)
  18. fmt.Println(data)
  19. }))
  20. Convey("CreateFile Error", t, WithDao(func(d *Dao) {
  21. httpMock("GET", url).Reply(200).Body(bytes.NewReader([]byte("test")))
  22. _, err := d.DownloadFile(ctx, url, "/test/test.txt")
  23. So(err, ShouldNotBeNil)
  24. fmt.Println(err)
  25. }))
  26. }