Files
tasks/tests/testcore/utils.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

100 lines
2.8 KiB
Go

package testcore
import (
"fmt"
"regexp"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
commonpb "go.temporal.io/api/common/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/sdk/converter"
"github.com/hanzoai/tasks/api/adminservice/v1"
historyspb "github.com/hanzoai/tasks/api/history/v1"
"github.com/hanzoai/tasks/api/historyservice/v1"
replicationspb "github.com/hanzoai/tasks/api/replication/v1"
"github.com/hanzoai/tasks/common/payloads"
"github.com/hanzoai/tasks/common/persistence/versionhistory"
"google.golang.org/protobuf/proto"
)
// TODO (alex): move this to functional_test_base.go as methods.
func RandomizeStr(id string) string {
return fmt.Sprintf("%v-%v", id, uuid.NewString())
}
func DecodeString(t require.TestingT, pls *commonpb.Payloads) string {
if th, ok := t.(interface{ Helper() }); ok {
th.Helper()
}
var str string
err := payloads.Decode(pls, &str)
require.NoError(t, err)
return str
}
func EventBatchesToVersionHistory(
versionHistory *historyspb.VersionHistory,
eventBatches []*historypb.History,
) (*historyspb.VersionHistory, error) {
// TODO temporary code to generate version history
// we should generate version as part of modeled based testing
if versionHistory == nil {
versionHistory = versionhistory.NewVersionHistory(nil, nil)
}
for _, batch := range eventBatches {
for _, event := range batch.Events {
err := versionhistory.AddOrUpdateVersionHistoryItem(versionHistory,
versionhistory.NewVersionHistoryItem(
event.GetEventId(),
event.GetVersion(),
))
if err != nil {
return nil, err
}
}
}
return versionHistory, nil
}
// MustToPayload converts a value to a Payload using the default data converter.
func MustToPayload(t require.TestingT, v any) *commonpb.Payload {
if th, ok := t.(interface{ Helper() }); ok {
th.Helper()
}
payload, err := converter.GetDefaultDataConverter().ToPayload(v)
require.NoError(t, err)
return payload
}
func RandomizedNexusEndpoint(name string) string {
re := regexp.MustCompile("[/_]")
safeName := re.ReplaceAllString(name, "-")
return fmt.Sprintf("%v-%v", safeName, uuid.NewString())
}
// ExtractReplicationMessages extracts WorkflowReplicationMessages from a proto message.
// This is a helper for tests that need to inspect replication message contents.
func ExtractReplicationMessages(msg proto.Message) *replicationspb.WorkflowReplicationMessages {
if msg == nil {
return nil
}
if histResp, ok := msg.(*historyservice.StreamWorkflowReplicationMessagesResponse); ok {
if messages := histResp.GetMessages(); messages != nil {
return messages
}
}
if adminResp, ok := msg.(*adminservice.StreamWorkflowReplicationMessagesResponse); ok {
if messages := adminResp.GetMessages(); messages != nil {
return messages
}
}
return nil
}