chore: update test

main
ZGGSONG 2 years ago
parent 4c02a0bce0
commit 5d66434e11

@ -0,0 +1,26 @@
package config
import (
"sendmsg/global"
"sendmsg/model"
"testing"
)
func TestConfig(t *testing.T) {
global.GLO_CONF_CH = make(chan model.Config)
config, err := InitConfig()
if err != nil {
t.Fatalf("Failed to initialize config: %v", err)
}
t.Log(config)
var count int
for {
if count > 5 {
return
}
config = <-global.GLO_CONF_CH
count++
t.Log(config)
}
}

@ -2,10 +2,13 @@ module sendmsg
go 1.19
require github.com/spf13/viper v1.15.0
require (
github.com/fsnotify/fsnotify v1.6.0
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/spf13/viper v1.15.0
)
require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect

@ -122,6 +122,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=

@ -1,6 +1,11 @@
package message
import "log"
import (
"fmt"
"github.com/jordan-wright/email"
"log"
"net/smtp"
)
type Mail struct {
Host string
@ -14,5 +19,15 @@ type Mail struct {
func (m *Mail) Send(body Body) {
log.Printf("[mail] sending message...")
log.Printf(body.Title + " " + body.Content)
e := email.NewEmail()
e.From = m.FromName
e.To = m.To
e.Subject = body.Title
e.Text = []byte(body.Content)
addr := fmt.Sprintf("%v:%v", m.Host, m.Port)
err := e.Send(addr, smtp.PlainAuth("", m.Username, m.Password, m.Host))
if err != nil {
log.Fatalf("[mail] send failed: %v\n", err)
}
log.Printf("[mail] send successful")
}

@ -15,8 +15,8 @@ func TestSend(t *testing.T) {
global.GLO_CONF = conf
m := GetType()
if !Enabled() {
return
if !Enabled() || m == nil {
t.Fatalf("[test] Failed to get type...")
}
m.Send(Body{
Title: "Hello",

Loading…
Cancel
Save