kis-flow/test/kis_function_test.go

39 lines
929 B
Go
Raw Normal View History

2024-01-01 17:49:27 +08:00
package test
2023-12-31 18:04:28 +08:00
import (
"context"
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/common"
"github.com/aceld/kis-flow/config"
"github.com/aceld/kis-flow/flow"
"github.com/aceld/kis-flow/function"
2023-12-31 18:04:28 +08:00
"testing"
)
func TestNewKisFunction(t *testing.T) {
ctx := context.Background()
2024-04-15 17:50:02 +08:00
// 1. Create a KisFunction configuration instance
2023-12-31 18:04:28 +08:00
source := config.KisSource{
2024-04-15 17:50:02 +08:00
Name: "TikTokOrder",
2023-12-31 18:04:28 +08:00
Must: []string{"order_id", "user_id"},
}
2024-01-03 10:16:54 +08:00
myFuncConfig1 := config.NewFuncConfig("funcName1", common.C, &source, nil)
2023-12-31 18:04:28 +08:00
if myFuncConfig1 == nil {
panic("myFuncConfig1 is nil")
}
2024-04-15 17:50:02 +08:00
// 2. Create a KisFlow configuration instance
2024-01-03 10:16:54 +08:00
myFlowConfig1 := config.NewFlowConfig("flowName1", common.FlowEnable)
2023-12-31 18:04:28 +08:00
2024-04-15 17:50:02 +08:00
// 3. Create a KisFlow object
2023-12-31 18:04:28 +08:00
flow1 := flow.NewKisFlow(myFlowConfig1)
2024-04-15 17:50:02 +08:00
// 4. Create a KisFunction object
2024-01-01 17:49:27 +08:00
func1 := function.NewKisFunction(flow1, myFuncConfig1)
2023-12-31 18:04:28 +08:00
if err := func1.Call(ctx, flow1); err != nil {
t.Errorf("func1.Call() error = %v", err)
}
}