service_test.go 734 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "log"
  6. "testing"
  7. "go-common/app/infra/notify/conf"
  8. "go-common/app/infra/notify/model"
  9. "go-common/library/ecode"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. s *Service
  14. )
  15. func TestMain(m *testing.M) {
  16. var err error
  17. flag.Set("conf", "../cmd/notify-test.toml")
  18. if err = conf.Init(); err != nil {
  19. log.Println(err)
  20. return
  21. }
  22. s = New(conf.Conf)
  23. m.Run()
  24. }
  25. func TestPub(t *testing.T) {
  26. s.pubConfs = map[string]*model.Pub{
  27. "test-test": &model.Pub{
  28. Topic: "test",
  29. Group: "test",
  30. },
  31. }
  32. Convey("test pub", t, func() {
  33. err := s.Pub(context.TODO(), &model.ArgPub{Topic: "test", Group: "test", AppSecret: "test"})
  34. So(err, ShouldEqual, ecode.AccessDenied)
  35. })
  36. }