mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
114 lines
3.9 KiB
Go
114 lines
3.9 KiB
Go
package frontend
|
|
|
|
import (
|
|
"testing"
|
|
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
schedulepb "go.temporal.io/api/schedule/v1"
|
|
workflowpb "go.temporal.io/api/workflow/v1"
|
|
schedulespb "github.com/hanzoai/tasks/api/schedule/v1"
|
|
"github.com/hanzoai/tasks/common/payload"
|
|
"github.com/hanzoai/tasks/common/persistence/visibility/manager"
|
|
"github.com/hanzoai/tasks/common/searchattribute"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestDescribeScheduleAnnotatesScheduledWorkflowWithTypes(t *testing.T) {
|
|
makeWorkflowHandler := func(
|
|
visibilityManager *manager.MockVisibilityManager,
|
|
searchAttrProvider *searchattribute.MockProvider,
|
|
) WorkflowHandler {
|
|
h := WorkflowHandler{
|
|
saMapperProvider: searchattribute.NewTestMapperProvider(&searchattribute.TestMapper{Namespace: "ns"}),
|
|
visibilityMgr: visibilityManager,
|
|
saProvider: searchAttrProvider,
|
|
}
|
|
return h
|
|
}
|
|
controller := gomock.NewController(t)
|
|
visibilityManager := makeVisibilityManagerStub(controller)
|
|
searchAttrProvider := makeSearchAttributesProviderStub(
|
|
controller,
|
|
map[string]enumspb.IndexedValueType{
|
|
"CustomKeywordField": enumspb.INDEXED_VALUE_TYPE_TEXT,
|
|
"CustomBoolField": enumspb.INDEXED_VALUE_TYPE_BOOL,
|
|
},
|
|
)
|
|
response := makeResponseWithScheduledWorkflowAttributes(
|
|
map[string]string{"CustomKeywordField": "keyword", "CustomBoolField": "true"})
|
|
|
|
h := makeWorkflowHandler(visibilityManager, searchAttrProvider)
|
|
|
|
err := h.annotateSearchAttributesOfScheduledWorkflow(response, "ns")
|
|
|
|
if err != nil {
|
|
t.Fatalf("error %v", err)
|
|
}
|
|
assertScheduledWorkflowSearchAttributeHasAssociatedTypeOf(
|
|
t, response, "CustomKeywordField", enumspb.INDEXED_VALUE_TYPE_TEXT)
|
|
assertScheduledWorkflowSearchAttributeHasAssociatedTypeOf(
|
|
t, response, "CustomBoolField", enumspb.INDEXED_VALUE_TYPE_BOOL)
|
|
}
|
|
|
|
func assertScheduledWorkflowSearchAttributeHasAssociatedTypeOf(
|
|
t *testing.T,
|
|
response *schedulespb.DescribeResponse,
|
|
searchAttribute string,
|
|
expectedType enumspb.IndexedValueType,
|
|
) {
|
|
t.Helper()
|
|
attributes := getScheduledWorkflowSearchAttributes(response)
|
|
actualAttributeType := attributes.IndexedFields["AliasFor"+searchAttribute].Metadata[searchattribute.MetadataType]
|
|
if string(actualAttributeType) != expectedType.String() {
|
|
t.Errorf(
|
|
"expected type %s for attribute %s, got %s",
|
|
expectedType.String(),
|
|
searchAttribute,
|
|
string(actualAttributeType),
|
|
)
|
|
}
|
|
}
|
|
|
|
func getScheduledWorkflowSearchAttributes(response *schedulespb.DescribeResponse) *commonpb.SearchAttributes {
|
|
return response.Schedule.Action.Action.(*schedulepb.ScheduleAction_StartWorkflow).StartWorkflow.SearchAttributes
|
|
}
|
|
|
|
func makeSearchAttributesProviderStub(
|
|
controller *gomock.Controller,
|
|
custom map[string]enumspb.IndexedValueType,
|
|
) *searchattribute.MockProvider {
|
|
searchAttrProvider := searchattribute.NewMockProvider(controller)
|
|
nameTypeMapStub := searchattribute.NewNameTypeMapStub(custom)
|
|
searchAttrProvider.EXPECT().GetSearchAttributes("index", false).Return(nameTypeMapStub, nil).AnyTimes()
|
|
return searchAttrProvider
|
|
}
|
|
|
|
func makeVisibilityManagerStub(controller *gomock.Controller) *manager.MockVisibilityManager {
|
|
visibilityManager := manager.NewMockVisibilityManager(controller)
|
|
visibilityManager.EXPECT().GetIndexName().Return("index").AnyTimes()
|
|
return visibilityManager
|
|
}
|
|
|
|
func makeResponseWithScheduledWorkflowAttributes(nameValueMap map[string]string) *schedulespb.DescribeResponse {
|
|
attributes := commonpb.SearchAttributes{
|
|
IndexedFields: map[string]*commonpb.Payload{},
|
|
}
|
|
for name, value := range nameValueMap {
|
|
attributes.IndexedFields["AliasFor"+name] = payload.EncodeString(value)
|
|
}
|
|
|
|
response := schedulespb.DescribeResponse{
|
|
Schedule: &schedulepb.Schedule{
|
|
Action: &schedulepb.ScheduleAction{
|
|
Action: &schedulepb.ScheduleAction_StartWorkflow{
|
|
StartWorkflow: &workflowpb.NewWorkflowExecutionInfo{
|
|
SearchAttributes: &attributes,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
return &response
|
|
}
|