Skip to content

Commit

Permalink
Upgrade v1.8.2 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl authored Feb 1, 2023
1 parent c35b23f commit c2855d6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
5 changes: 4 additions & 1 deletion database/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ type Orm struct {
func NewOrm(ctx context.Context) *Orm {
defaultConnection := facades.Config.GetString("database.default")
gormDB, err := databasegorm.NewDB(ctx, defaultConnection)
if err != nil || gormDB == nil {
if err != nil {
color.Redln(fmt.Sprintf("[Orm] Init %s connection error: %v", defaultConnection, err))

return nil
}
if gormDB == nil {
return nil
}

return &Orm{
ctx: ctx,
Expand Down
4 changes: 2 additions & 2 deletions log/logrus_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package log
import (
"errors"

"github.com/sirupsen/logrus"

"github.com/goravel/framework/contracts/log"
"github.com/goravel/framework/facades"
"github.com/goravel/framework/log/logger"

"github.com/sirupsen/logrus"
)

type Writer struct {
Expand Down
18 changes: 14 additions & 4 deletions mail/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,20 @@ func SendMail(subject, html string, fromAddress, fromName string, to, cc, bcc, a
}
}

return e.SendWithStartTLS(fmt.Sprintf("%s:%s", facades.Config.GetString("mail.host"),
facades.Config.GetString("mail.port")),
LoginAuth(facades.Config.GetString("mail.username"),
facades.Config.GetString("mail.password")), &tls.Config{ServerName: facades.Config.GetString("mail.host")})
port := facades.Config.GetInt("mail.port")
switch port {
case 465:
return e.SendWithTLS(fmt.Sprintf("%s:%s", facades.Config.GetString("mail.host"), facades.Config.GetString("mail.port")),
LoginAuth(facades.Config.GetString("mail.username"), facades.Config.GetString("mail.password")),
&tls.Config{ServerName: facades.Config.GetString("mail.host")})
case 587:
return e.SendWithStartTLS(fmt.Sprintf("%s:%s", facades.Config.GetString("mail.host"), facades.Config.GetString("mail.port")),
LoginAuth(facades.Config.GetString("mail.username"), facades.Config.GetString("mail.password")),
&tls.Config{ServerName: facades.Config.GetString("mail.host")})
default:
return e.Send(fmt.Sprintf("%s:%d", facades.Config.GetString("mail.host"), port),
LoginAuth(facades.Config.GetString("mail.username"), facades.Config.GetString("mail.password")))
}
}

type loginAuth struct {
Expand Down
40 changes: 39 additions & 1 deletion mail/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,45 @@ func (s *ApplicationTestSuite) SetupTest() {

}

func (s *ApplicationTestSuite) TestSendMail() {
func (s *ApplicationTestSuite) TestSendMailBy25Port() {
facades.Config.Add("mail", map[string]any{
"host": facades.Config.Env("MAIL_HOST", ""),
"port": 25,
"from": map[string]any{
"address": facades.Config.Env("MAIL_FROM_ADDRESS", "[email protected]"),
"name": facades.Config.Env("MAIL_FROM_NAME", "Example"),
},
"username": facades.Config.Env("MAIL_USERNAME"),
"password": facades.Config.Env("MAIL_PASSWORD"),
})
s.Nil(facades.Mail.To([]string{facades.Config.Env("MAIL_TO").(string)}).
Cc([]string{facades.Config.Env("MAIL_CC").(string)}).
Bcc([]string{facades.Config.Env("MAIL_BCC").(string)}).
Attach([]string{"../logo.png"}).
Content(mail.Content{Subject: "Goravel Test", Html: "<h1>Hello Goravel</h1>"}).
Send())
}

func (s *ApplicationTestSuite) TestSendMailBy465Port() {
facades.Config.Add("mail", map[string]any{
"host": facades.Config.Env("MAIL_HOST", ""),
"port": 465,
"from": map[string]any{
"address": facades.Config.Env("MAIL_FROM_ADDRESS", "[email protected]"),
"name": facades.Config.Env("MAIL_FROM_NAME", "Example"),
},
"username": facades.Config.Env("MAIL_USERNAME"),
"password": facades.Config.Env("MAIL_PASSWORD"),
})
s.Nil(facades.Mail.To([]string{facades.Config.Env("MAIL_TO").(string)}).
Cc([]string{facades.Config.Env("MAIL_CC").(string)}).
Bcc([]string{facades.Config.Env("MAIL_BCC").(string)}).
Attach([]string{"../logo.png"}).
Content(mail.Content{Subject: "Goravel Test", Html: "<h1>Hello Goravel</h1>"}).
Send())
}

func (s *ApplicationTestSuite) TestSendMailBy587Port() {
s.Nil(facades.Mail.To([]string{facades.Config.Env("MAIL_TO").(string)}).
Cc([]string{facades.Config.Env("MAIL_CC").(string)}).
Bcc([]string{facades.Config.Env("MAIL_BCC").(string)}).
Expand Down

0 comments on commit c2855d6

Please sign in to comment.