merak_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package cms
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoSendWechat(t *testing.T) {
  10. convey.Convey("SendWechat", t, func(ctx convey.C) {
  11. var (
  12. content = "测试内容"
  13. title = "测试标题"
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. err := d.MerakNotify(context.Background(), content, title)
  17. fmt.Println(err)
  18. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoGetMerakSign(t *testing.T) {
  25. convey.Convey("sign", t, func(ctx convey.C) {
  26. var (
  27. params = map[string]string{
  28. "Action": "CreateWechatMessage",
  29. "PublicKey": "1",
  30. "UserName": strings.Join([]string{"user1", "user2"}, ","),
  31. "Title": "测试标题",
  32. "Content": "测试内容",
  33. "TreeId": "",
  34. }
  35. )
  36. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  37. p1, err := MerakSign(params, "secret")
  38. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldEqual, "59cd4e74b225a7d326ee7d6c89bf27cf2f6015dc")
  43. })
  44. })
  45. })
  46. }