upload_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "io"
  6. "os"
  7. "testing"
  8. "go-common/app/admin/main/up/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestMain(m *testing.M) {
  12. if os.Getenv("DEPLOY_ENV") != "" {
  13. flag.Set("app_id", "main.archive.up-admin")
  14. flag.Set("conf_token", "930697bb7def4df0713ef8080596b863")
  15. flag.Set("tree_id", "36438")
  16. flag.Set("conf_version", "1")
  17. flag.Set("deploy_env", "uat")
  18. flag.Set("conf_host", "config.bilibili.co")
  19. flag.Set("conf_path", "/tmp")
  20. flag.Set("region", "sh")
  21. flag.Set("zone", "sh001")
  22. } else {
  23. flag.Set("conf", "../cmd/up-admin.toml")
  24. }
  25. if os.Getenv("UT_LOCAL_TEST") != "" {
  26. flag.Set("conf", "../cmd/up-admin.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. os.Exit(m.Run())
  33. }
  34. func TestDaoUpload(t *testing.T) {
  35. convey.Convey("Upload", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. fileName = ""
  39. fileType = ""
  40. expire = int64(0)
  41. body io.Reader
  42. bfsConf = &conf.Bfs{}
  43. )
  44. //defer gock.OffAll()
  45. //httpMock("PUT", bfsConf.Addr+uploadurl).Reply(200)
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. location, err := Upload(c, fileName, fileType, expire, body, bfsConf)
  48. ctx.Convey("Then err should be nil.location should not be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldNotBeNil)
  50. ctx.So(location, convey.ShouldEqual, "")
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoAuthorize(t *testing.T) {
  56. convey.Convey("Authorize", t, func(ctx convey.C) {
  57. var (
  58. key = ""
  59. secret = ""
  60. method = ""
  61. bucket = ""
  62. file = ""
  63. expire = int64(0)
  64. )
  65. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  66. authorization := Authorize(key, secret, method, bucket, file, expire)
  67. ctx.Convey("Then authorization should not be nil.", func(ctx convey.C) {
  68. ctx.So(authorization, convey.ShouldNotBeNil)
  69. })
  70. })
  71. })
  72. }