Files
tasks/tests/ndc/test_data.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

75 lines
2.0 KiB
Go

package ndc
import (
"encoding/json"
"errors"
"fmt"
"os"
historypb "go.temporal.io/api/history/v1"
replicationpb "go.temporal.io/api/replication/v1"
historyspb "github.com/hanzoai/tasks/api/history/v1"
"github.com/hanzoai/tasks/common/codec"
"github.com/hanzoai/tasks/tests/testcore"
)
var (
clusterName = []string{"cluster-a", "cluster-b", "cluster-c"}
clusterReplicationConfig = []*replicationpb.ClusterReplicationConfig{
{ClusterName: clusterName[0]},
{ClusterName: clusterName[1]},
{ClusterName: clusterName[2]},
}
)
func GetEventBatchesFromTestEvents(fileName string, workflowId string) ([][]*historypb.HistoryEvent, *historyspb.VersionHistory, error) {
filePath := "./testevents/" + fileName
content, err := os.ReadFile(filePath)
if err != nil {
return nil, nil, err
}
var result map[string]any
// Unmarshal the JSON data into a map
err = json.Unmarshal(content, &result)
if err != nil {
return nil, nil, err
}
batches, ok := result[workflowId].([]any)
if !ok {
return nil, nil, errors.New("workflowId not found in test data")
}
var elements [][]byte
for i, v := range batches {
subArray, ok := v.([]any)
if !ok {
return nil, nil, fmt.Errorf("element %d is not a sub-array, is type %s", i, fmt.Sprintf("%T", v))
}
temp, err := json.Marshal(subArray)
if err != nil {
return nil, nil, err
}
elements = append(elements, temp)
}
historyBatches := make([][]*historypb.HistoryEvent, len(batches))
encoder := codec.NewJSONPBEncoder()
for i, batch := range elements {
historyEvents, err := encoder.DecodeHistoryEvents(batch)
if err != nil {
return nil, nil, err
}
historyBatches[i] = historyEvents
}
var eventsFlatted []*historypb.HistoryEvent
for _, batch := range historyBatches {
eventsFlatted = append(eventsFlatted, batch...)
}
versionHistory, err := testcore.EventBatchesToVersionHistory(nil, []*historypb.History{
{Events: eventsFlatted},
})
if err != nil {
return nil, nil, err
}
return historyBatches, versionHistory, nil
}