mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
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 "go.temporal.io/server/api/schedule/v1"
|
|
"go.temporal.io/server/common/payload"
|
|
"go.temporal.io/server/common/persistence/visibility/manager"
|
|
"go.temporal.io/server/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
|
|
}
|