hotalert/task/task_test.go

46 lines
923 B
Go
Raw Normal View History

2022-11-03 20:04:14 +00:00
package task
import (
"errors"
2022-11-03 20:04:14 +00:00
"github.com/stretchr/testify/assert"
"hotalert/alert"
"testing"
"time"
)
func Test_NewTask(t *testing.T) {
var task = NewTask("web_scrape", Options{
2022-11-03 20:04:14 +00:00
"option": "true",
}, alert.NewDummyAlerter())
assert.Equal(t, Task{
ExecutionFuncName: "web_scrape",
2022-11-03 20:04:14 +00:00
Options: Options{
"option": "true",
},
Timeout: 10 * time.Second,
Alerter: alert.NewDummyAlerter(),
Callback: nil,
}, *task)
}
func Test_NewResult(t *testing.T) {
var task = NewTask("web_scrape", Options{
2022-11-03 20:04:14 +00:00
"option": "true",
}, alert.NewDummyAlerter())
testError := errors.New("test error")
2022-11-03 20:04:14 +00:00
var result = NewResult(task)
result.SetError(testError)
2022-11-03 20:04:14 +00:00
assert.Equal(t, Result{
InitialTask: &Task{
ExecutionFuncName: "web_scrape",
2022-11-03 20:04:14 +00:00
Options: Options{
"option": "true",
},
Timeout: 10 * time.Second,
Alerter: alert.NewDummyAlerter(),
Callback: nil,
},
error: testError,
2022-11-03 20:04:14 +00:00
}, *result)
}