api_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoMyInfo(t *testing.T) {
  8. var (
  9. c = context.TODO()
  10. accessKey = "123456"
  11. )
  12. convey.Convey("MyInfo", t, func(ctx convey.C) {
  13. accountInfo, err := d.MyInfo(c, accessKey)
  14. ctx.Convey("Then err should be nil.accountInfo should not be nil.", func(ctx convey.C) {
  15. ctx.So(err, convey.ShouldNotBeNil)
  16. ctx.So(accountInfo, convey.ShouldBeNil)
  17. })
  18. })
  19. }
  20. func TestDaoOauth(t *testing.T) {
  21. var (
  22. c = context.TODO()
  23. uri = "https://wwww.baidu.com"
  24. accessKey = "123456"
  25. from = "baidu"
  26. )
  27. convey.Convey("Oauth", t, func(ctx convey.C) {
  28. token, err := d.Oauth(c, uri, accessKey, from)
  29. ctx.Convey("Then err should be nil.token should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldNotBeNil)
  31. ctx.So(token, convey.ShouldBeNil)
  32. })
  33. })
  34. }
  35. func TestDaoLogin(t *testing.T) {
  36. var (
  37. c = context.TODO()
  38. query = "123"
  39. cookie = "123"
  40. )
  41. convey.Convey("Login", t, func(ctx convey.C) {
  42. loginToken, err := d.Login(c, query, cookie)
  43. ctx.Convey("Then err should be nil.loginToken should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldNotBeNil)
  45. ctx.So(loginToken, convey.ShouldBeNil)
  46. })
  47. })
  48. }
  49. func TestDaoLoginOrigin(t *testing.T) {
  50. var (
  51. c = context.TODO()
  52. userid = "1"
  53. rsaPwd = "123456"
  54. )
  55. convey.Convey("LoginOrigin", t, func(ctx convey.C) {
  56. loginToken, err := d.LoginOrigin(c, userid, rsaPwd)
  57. ctx.Convey("Then err should be nil.loginToken should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldNotBeNil)
  59. ctx.So(loginToken, convey.ShouldBeNil)
  60. })
  61. })
  62. }
  63. func TestDaoRSAKeyOrigin(t *testing.T) {
  64. var (
  65. c = context.TODO()
  66. )
  67. convey.Convey("RSAKeyOrigin", t, func(ctx convey.C) {
  68. key, err := d.RSAKeyOrigin(c)
  69. ctx.Convey("Then err should be nil.key should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(key, convey.ShouldNotBeNil)
  72. })
  73. })
  74. }
  75. func TestDaoRenewToken(t *testing.T) {
  76. var (
  77. c = context.TODO()
  78. uri = "https://wwww.baidu.com"
  79. ak = "234"
  80. from = "234"
  81. )
  82. convey.Convey("RenewToken", t, func(ctx convey.C) {
  83. renewToken, err := d.RenewToken(c, uri, ak, from)
  84. ctx.Convey("Then err should be nil.renewToken should not be nil.", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldNotBeNil)
  86. ctx.So(renewToken, convey.ShouldBeNil)
  87. })
  88. })
  89. }