Skip to content

Commit

Permalink
Merge main into sweep/fix-lint-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Nov 3, 2023
2 parents bf26df6 + 595d5f3 commit a4ebf91
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/email/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewMail() (Mail, error) {
config.Config.VerifyCode.Mail.SmtpPort,
config.Config.VerifyCode.Mail.SenderMail,
config.Config.VerifyCode.Mail.SenderAuthorizationCode)

return &mail{dail: dail}, nil
}

Expand Down
62 changes: 62 additions & 0 deletions pkg/email/mail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package email

import (
"context"
"errors"
"github.com/OpenIMSDK/chat/pkg/common/config"
"gopkg.in/yaml.v3"
"io/ioutil"
"testing"
)

func TestEmail(T *testing.T) {
if err := InitConfig(); err != nil {
panic(err)
}
tests := []struct {
name string
ctx context.Context
mail string
code string
want error
}{
{
name: "success send email",
ctx: context.Background(),
mail: "[email protected]",
code: "5555",
want: errors.New("nil"),
},
{
name: "fail send email",
ctx: context.Background(),
mail: "",
code: "5555",
want: errors.New("dial tcp :0: connectex: The requested address is not valid in its context."),
},
}
mail, err := NewMail()
if err != nil {
T.Errorf("Init mail failed,%v", err)
}

for _, tt := range tests {
T.Run(tt.name, func(t *testing.T) {
if got := mail.SendMail(tt.ctx, tt.mail, tt.code); errors.Is(got, tt.want) {
t.Errorf("%v have a err,%v", tt.name, tt.want)
}
})
}
}

func InitConfig() error {
yam, err := ioutil.ReadFile("../../config/config.yaml")
if err != nil {
return err
}
err = yaml.Unmarshal(yam, &config.Config)
if err != nil {
return err
}
return nil
}

0 comments on commit a4ebf91

Please sign in to comment.