upload_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package bfs
  2. import (
  3. "context"
  4. "io"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func TestBfsUpload(t *testing.T) {
  10. convey.Convey("Upload", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. fileName = ""
  14. fileType = ""
  15. expire = int64(0)
  16. body io.Reader
  17. )
  18. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  19. defer gock.OffAll()
  20. httpMock("PUT", d.bfs).Reply(200).SetHeader("code", "200").SetHeader("Location", "baidu")
  21. location, err := d.Upload(c, fileName, fileType, expire, body)
  22. ctx.Convey("Then err should be nil.location should not be nil.", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. ctx.So(location, convey.ShouldNotBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestBfsauthorize(t *testing.T) {
  30. convey.Convey("authorize", t, func(ctx convey.C) {
  31. var (
  32. key = ""
  33. secret = ""
  34. method = ""
  35. bucket = ""
  36. file = ""
  37. expire = int64(0)
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. authorization := authorize(key, secret, method, bucket, file, expire)
  41. ctx.Convey("Then authorization should not be nil.", func(ctx convey.C) {
  42. ctx.So(authorization, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }