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