up_nas_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "testing"
  7. "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoSign(t *testing.T) {
  11. var (
  12. params = url.Values{}
  13. nas = d.c.Nas
  14. )
  15. params.Set("appkey", nas.Key)
  16. params.Set("appsecret", nas.Secret)
  17. params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
  18. convey.Convey("Sign", t, func(ctx convey.C) {
  19. query, err := Sign(params)
  20. ctx.Convey("Then err should be nil.query should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(query, convey.ShouldNotBeNil)
  23. })
  24. })
  25. }
  26. func TestDaogetSign(t *testing.T) {
  27. var nas = d.c.Nas
  28. convey.Convey("getSign", t, func(ctx convey.C) {
  29. uri, err := getSign(nas)
  30. ctx.Convey("Then err should be nil.uri should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. ctx.So(uri, convey.ShouldNotBeNil)
  33. })
  34. })
  35. }
  36. func TestDaoUploadNas(t *testing.T) {
  37. var (
  38. c = context.Background()
  39. fileName = "test.txt"
  40. data = []byte("test123")
  41. nas = d.c.Nas
  42. )
  43. convey.Convey("UploadNas", t, func(ctx convey.C) {
  44. location, err := d.UploadNas(c, fileName, data, nas)
  45. ctx.Convey("Then err should be nil.location should not be nil.", func(ctx convey.C) {
  46. ctx.So(err, convey.ShouldBeNil)
  47. ctx.So(location, convey.ShouldNotBeNil)
  48. })
  49. })
  50. }