cookie_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/job/main/passport-auth/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoAddCookie(t *testing.T) {
  10. convey.Convey("AddCookie", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. cookie = &model.Cookie{}
  14. session = []byte("712b7a22,1535703191,c07e44d8")
  15. csrf = []byte("0273f9216fa8d6d77c3dd5499a1d0d4a")
  16. ct = time.Now()
  17. )
  18. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  19. affected, err := d.AddCookie(c, cookie, session, csrf, ct)
  20. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(affected, convey.ShouldNotBeNil)
  23. })
  24. })
  25. })
  26. }
  27. func TestDaoDelCookie(t *testing.T) {
  28. convey.Convey("DelCookie", t, func(ctx convey.C) {
  29. var (
  30. c = context.Background()
  31. session = []byte("712b7a22,1535703191,c07e44d8")
  32. ct = time.Now()
  33. )
  34. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  35. affected, err := d.DelCookie(c, session, ct)
  36. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  37. ctx.So(err, convey.ShouldBeNil)
  38. ctx.So(affected, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoAddCookieDeleted(t *testing.T) {
  44. convey.Convey("AddCookieDeleted", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. cookie = &model.Cookie{}
  48. session = []byte("712b7a22,1535703191,c07e44d8")
  49. csrf = []byte("0273f9216fa8d6d77c3dd5499a1d0d4a")
  50. ct = time.Now()
  51. )
  52. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  53. affected, err := d.AddCookieDeleted(c, cookie, session, csrf, ct)
  54. ctx.Convey("Then err should be nil.affected should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(affected, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }