upload_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoauthorize(t *testing.T) {
  8. convey.Convey("authorize", t, func(ctx convey.C) {
  9. var (
  10. key = d.c.Bfs.Key
  11. secret = d.c.Bfs.Secret
  12. method = "PUT"
  13. bucket = d.c.Bfs.Bucket
  14. expire = int64(1)
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. authorization := authorize(key, secret, method, bucket, expire)
  18. ctx.Convey("Then authorization should not be nil.", func(ctx convey.C) {
  19. ctx.So(authorization, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoUploadProxy(t *testing.T) {
  25. convey.Convey("UploadProxy", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. fileType = ""
  29. expire = int64(1)
  30. body = []byte("")
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. httpMock("PUT", d.c.Bfs.Addr+"/"+d.c.Bfs.Bucket).Reply(200).SetHeader("Code", "200")
  34. url, err := d.UploadProxy(c, fileType, expire, body)
  35. ctx.Convey("Then err should be nil.url should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(url, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }