feat:增加测试用例

This commit is contained in:
songzhibin97
2021-09-15 18:42:17 +08:00
parent d80edb16df
commit 0f18854c40
5 changed files with 70 additions and 3 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ import (
//@param: str []byte
//@return: string
func MD5V(str []byte) string {
func MD5V(str []byte, b ...byte) string {
h := md5.New()
h.Write(str)
return hex.EncodeToString(h.Sum(nil))
return hex.EncodeToString(h.Sum(b))
}
+1 -1
View File
@@ -82,7 +82,7 @@ func loadPlugin(path string, f fs.FileInfo) error {
fmt.Println("loadPlugin err ", fmt.Sprintf("path:%s 没有实现 %s 接口", filepath.Base(fPath), OnlyFuncName))
return errors.New("没有实现指定接口")
} else {
// todo
}
fmt.Println("loadPlugin add ", filepath.Base(fPath))
ManagementPlugin.SetPlugin(filepath.Base(fPath), p)
+65
View File
@@ -0,0 +1,65 @@
package timer
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var job = mockJob{}
type mockJob struct{}
func (job mockJob) Run() {
mockFunc()
}
func mockFunc() {
time.Sleep(time.Second)
fmt.Println("1s...")
}
func TestNewTimerTask(t *testing.T) {
tm := NewTimerTask()
_tm := tm.(*timer)
{
_, err := tm.AddTaskByFunc("func", "@every 1s", mockFunc)
assert.Nil(t, err)
_, ok := _tm.taskList["func"]
if !ok {
t.Error("no find func")
}
}
{
_, err := tm.AddTaskByJob("job", "@every 1s", job)
assert.Nil(t, err)
_, ok := _tm.taskList["job"]
if !ok {
t.Error("no find job")
}
}
{
_, ok := tm.FindCron("func")
if !ok {
t.Error("no find func")
}
_, ok = tm.FindCron("job")
if !ok {
t.Error("no find job")
}
_, ok = tm.FindCron("none")
if ok {
t.Error("find none")
}
}
{
tm.Clear("func")
_, ok := tm.FindCron("func")
if ok {
t.Error("find func")
}
}
}