29 lines
1.1 KiB
Go
29 lines
1.1 KiB
Go
package flow
|
|
|
|
import (
|
|
"testing"
|
|
|
|
flowDao "ai-agent/workflow/dao/flow"
|
|
"ai-agent/workflow/model/entity"
|
|
)
|
|
|
|
func TestAsyncCallAction(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
rec *entity.FlowAsyncTask
|
|
want asyncAction
|
|
}{
|
|
{"无记录 → 重新提交", nil, asyncActionResubmit},
|
|
{"done 有结果 → 复用", &entity.FlowAsyncTask{State: flowDao.FlowAsyncStateDone, Result: `{"taskId":1}`}, asyncActionReuse},
|
|
{"done 空结果 → 重新提交", &entity.FlowAsyncTask{State: flowDao.FlowAsyncStateDone, Result: ""}, asyncActionResubmit},
|
|
{"done 空对象 → 重新提交", &entity.FlowAsyncTask{State: flowDao.FlowAsyncStateDone, Result: "{}"}, asyncActionResubmit},
|
|
{"failed → 重新提交", &entity.FlowAsyncTask{State: flowDao.FlowAsyncStateFailed}, asyncActionResubmit},
|
|
{"in-flight → 重订阅收尾", &entity.FlowAsyncTask{State: flowDao.FlowAsyncStateInflight, MsgTopic: "model-call-x"}, asyncActionFinalize},
|
|
}
|
|
for _, c := range cases {
|
|
if got := asyncCallAction(c.rec); got != c.want {
|
|
t.Fatalf("%s: got %v want %v", c.name, got, c.want)
|
|
}
|
|
}
|
|
}
|