kis-flow/test/kis_action_test.go

102 lines
2.3 KiB
Go
Raw Normal View History

2024-01-23 16:24:16 +08:00
package test
import (
"context"
"fmt"
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/file"
"github.com/aceld/kis-flow/kis"
2024-01-23 16:24:16 +08:00
"testing"
)
func TestActionAbort(t *testing.T) {
ctx := context.Background()
2024-04-15 17:50:02 +08:00
// 1. Load the configuration file and build the Flow
2024-03-20 18:09:08 +08:00
if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
2024-01-23 16:24:16 +08:00
panic(err)
}
2024-04-15 17:50:02 +08:00
// 2. Get the Flow
2024-01-23 16:24:16 +08:00
flow1 := kis.Pool().GetFlow("flowName2")
2024-04-15 17:50:02 +08:00
// 3. Commit original data
2024-01-23 16:24:16 +08:00
_ = flow1.CommitRow("This is Data1 from Test")
_ = flow1.CommitRow("This is Data2 from Test")
_ = flow1.CommitRow("This is Data3 from Test")
2024-04-15 17:50:02 +08:00
// 4. Execute flow1
2024-01-23 16:24:16 +08:00
if err := flow1.Run(ctx); err != nil {
panic(err)
}
}
func TestActionDataReuse(t *testing.T) {
ctx := context.Background()
2024-04-15 17:50:02 +08:00
// 1. Load the configuration file and build the Flow
2024-03-20 18:09:08 +08:00
if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
2024-01-23 16:24:16 +08:00
panic(err)
}
2024-04-15 17:50:02 +08:00
// 2. Get the Flow
2024-01-23 16:24:16 +08:00
flow1 := kis.Pool().GetFlow("flowName3")
2024-04-15 17:50:02 +08:00
// 3. Commit original data
2024-01-23 16:24:16 +08:00
_ = flow1.CommitRow("This is Data1 from Test")
_ = flow1.CommitRow("This is Data2 from Test")
_ = flow1.CommitRow("This is Data3 from Test")
2024-04-15 17:50:02 +08:00
// 4. Execute flow1
2024-01-23 16:24:16 +08:00
if err := flow1.Run(ctx); err != nil {
panic(err)
}
}
func TestActionForceEntry(t *testing.T) {
ctx := context.Background()
2024-04-15 17:50:02 +08:00
// 1. Load the configuration file and build the Flow
2024-03-20 18:09:08 +08:00
if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
2024-01-23 16:24:16 +08:00
panic(err)
}
2024-04-15 17:50:02 +08:00
// 2. Get the Flow
2024-01-23 16:24:16 +08:00
flow1 := kis.Pool().GetFlow("flowName4")
2024-04-15 17:50:02 +08:00
// 3. Commit original data
2024-01-23 16:24:16 +08:00
_ = flow1.CommitRow("This is Data1 from Test")
_ = flow1.CommitRow("This is Data2 from Test")
_ = flow1.CommitRow("This is Data3 from Test")
2024-04-15 17:50:02 +08:00
// 4. Execute flow1
2024-01-23 16:24:16 +08:00
if err := flow1.Run(ctx); err != nil {
panic(err)
}
}
func TestActionJumpFunc(t *testing.T) {
ctx := context.Background()
2024-04-15 17:50:02 +08:00
// 1. Load the configuration file and build the Flow
2024-03-20 18:09:08 +08:00
if err := file.ConfigImportYaml("load_conf/"); err != nil {
fmt.Println("Wrong Config Yaml Path!")
2024-01-23 16:24:16 +08:00
panic(err)
}
2024-04-15 17:50:02 +08:00
// 2. Get the Flow
2024-01-23 16:24:16 +08:00
flow1 := kis.Pool().GetFlow("flowName5")
2024-04-15 17:50:02 +08:00
// 3. Commit original data
2024-01-23 16:24:16 +08:00
_ = flow1.CommitRow("This is Data1 from Test")
_ = flow1.CommitRow("This is Data2 from Test")
_ = flow1.CommitRow("This is Data3 from Test")
2024-04-15 17:50:02 +08:00
// 4. Execute flow1
2024-01-23 16:24:16 +08:00
if err := flow1.Run(ctx); err != nil {
panic(err)
}
}