Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinnrry committed Apr 30, 2024
1 parent 7df67dc commit 6b22de8
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 67 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ The code is in `server` folder.

`make build`

4、
4、Unit test

`make test`

## Api Documentation

Expand Down
6 changes: 5 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ SMTP端口: 25/465(SSL)

后端代码进入 `server`文件夹,运行 `main.go`文件

3、编译该项目
3、编译项目

`make build`

4、单元测试

`make test`

## 后端接口文档

[go to wiki](https://github.com/Jinnrry/PMail/wiki/%E5%90%8E%E7%AB%AF%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3)
Expand Down
1 change: 0 additions & 1 deletion server/dto/parsemail/email_decode_test.go

This file was deleted.

10 changes: 10 additions & 0 deletions server/hooks/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func NewHookSender(socketPath string, name string, serverVersion string) *HookSe
}
}

var processList []*os.Process

// Init 注册hook对象
func Init(serverVersion string) {

Expand Down Expand Up @@ -184,6 +186,7 @@ func Init(serverVersion string) {
return nil
}
fmt.Printf("[%s] Plugin Start! PID:%d", info.Name(), p.Pid)
processList = append(processList, p)

pluginNo++

Expand Down Expand Up @@ -214,3 +217,10 @@ func Init(serverVersion string) {
})

}

func Stop() {
log.Info("Plugin Stop")
for _, process := range processList {
process.Kill()
}
}
7 changes: 0 additions & 7 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"pmail/config"
"pmail/cron_server"
"pmail/res_init"
"pmail/signal"
"pmail/utils/context"
"time"
)
Expand Down Expand Up @@ -96,9 +95,3 @@ func main() {
log.Warnf("Server Stoped \n")

}

func stop() {
log.Warnf("Server Stop \n")
signal.RestartChan <- true
log.Warnf("Server Stop2 \n")
}
16 changes: 5 additions & 11 deletions server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import (
var httpClient *http.Client

func TestMain(m *testing.M) {

fmt.Println("!!!!!TestMain!!!!!!!!")

cookeieJar, err := cookiejar.New(nil)
if err != nil {
panic(err)
Expand All @@ -34,21 +31,18 @@ func TestMain(m *testing.M) {
httpClient = &http.Client{Jar: cookeieJar, Timeout: 5 * time.Second}
os.Remove("config/config.json")
os.Remove("config/pmail_temp.db")
go main()
go func() {
main()
}()
time.Sleep(3 * time.Second)

m.Run()
fmt.Println("!!!!!TestMain!!!!!!!!")
time.Sleep(5 * time.Second)
stop()
signal.RestartChan <- false
fmt.Println("!!!!!TestMain!!!!!!!!")

signal.StopChan <- true
time.Sleep(3 * time.Second)
}

func TestMaster(t *testing.T) {
fmt.Println("!!!!!TestMaster!!!!!!!!")

t.Run("TestPort", testPort)
t.Run("testDataBaseSet", testDataBaseSet)
t.Run("testPwdSet", testPwdSet)
Expand Down
24 changes: 17 additions & 7 deletions server/res_init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ func Init(serverVersion string) {
configStr, _ := json.Marshal(config.Instance)
log.Warnf("Config File Info: %s", configStr)

restart := <-signal.RestartChan
log.Infof("Server Restart!")
smtp_server.Stop()
http_server.HttpsStop()
http_server.HttpStop()
pop3_server.Stop()
log.Warnf("!!!!!ASDFASDF!!!!%+v", restart)
select {
case <-signal.RestartChan:
log.Infof("Server Restart!")
smtp_server.Stop()
http_server.HttpsStop()
http_server.HttpStop()
pop3_server.Stop()
hooks.Stop()
case <-signal.StopChan:
log.Infof("Server Stop!")
smtp_server.Stop()
http_server.HttpsStop()
http_server.HttpStop()
pop3_server.Stop()
hooks.Stop()
return
}

}

Expand Down
6 changes: 6 additions & 0 deletions server/signal/signal.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package signal

// InitChan 控制初始化流程结束
var InitChan = make(chan bool)

// RestartChan 控制程序重启
var RestartChan = make(chan bool)

// StopChan 控制程序结束
var StopChan = make(chan bool)
29 changes: 0 additions & 29 deletions server/utils/errors/error_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions server/utils/password/encode_test.go

This file was deleted.

0 comments on commit 6b22de8

Please sign in to comment.