diff --git a/temporalnexus/link_converter.go b/temporalnexus/link_converter.go index 2c25ca1b6..fbb6b22af 100644 --- a/temporalnexus/link_converter.go +++ b/temporalnexus/link_converter.go @@ -59,6 +59,7 @@ var ( rePatternWorkflowID, rePatternRunID, )) + eventReferenceType = string((&commonpb.Link_WorkflowEvent_EventReference{}).ProtoReflect().Descriptor().Name()) ) // ConvertLinkWorkflowEventToNexusLink converts a Link_WorkflowEvent type to Nexus Link. @@ -128,7 +129,7 @@ func ConvertNexusLinkToLinkWorkflowEvent(link nexus.Link) (*commonpb.Link_Workfl } switch refType := link.URL.Query().Get(linkWorkflowEventReferenceTypeKey); refType { - case string((&commonpb.Link_WorkflowEvent_EventReference{}).ProtoReflect().Descriptor().Name()): + case eventReferenceType: eventRef, err := convertURLQueryToLinkWorkflowEventEventReference(link.URL.Query()) if err != nil { return nil, fmt.Errorf("failed to parse link to Link_WorkflowEvent: %w", err) @@ -148,11 +149,11 @@ func ConvertNexusLinkToLinkWorkflowEvent(link nexus.Link) (*commonpb.Link_Workfl func convertLinkWorkflowEventEventReferenceToURLQuery(eventRef *commonpb.Link_WorkflowEvent_EventReference) string { values := url.Values{} - values.Set(linkWorkflowEventReferenceTypeKey, string(eventRef.ProtoReflect().Descriptor().Name())) + values.Set(linkWorkflowEventReferenceTypeKey, eventReferenceType) if eventRef.GetEventId() > 0 { values.Set(linkEventReferenceEventIDKey, strconv.FormatInt(eventRef.GetEventId(), 10)) } - values.Set(linkEventReferenceEventTypeKey, eventRef.GetEventType().String()) + values.Set(linkEventReferenceEventTypeKey, enumspb.EventType_name[int32(eventRef.GetEventType())]) return values.Encode() } diff --git a/temporalnexus/link_converter_test.go b/temporalnexus/link_converter_test.go index bd344a596..d8c8e9807 100644 --- a/temporalnexus/link_converter_test.go +++ b/temporalnexus/link_converter_test.go @@ -63,11 +63,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, - outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, { name: "valid with angle bracket", @@ -87,11 +87,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id>/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id%3E/run-id/history", - RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, - outputURL: "temporal:///namespaces/ns/workflows/wf-id%3E/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + outputURL: "temporal:///namespaces/ns/workflows/wf-id%3E/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, { name: "valid with slash", @@ -111,11 +111,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id//run-id/history", RawPath: "/namespaces/ns/workflows/wf-id%2F/run-id/history", - RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, - outputURL: "temporal:///namespaces/ns/workflows/wf-id%2F/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", + outputURL: "temporal:///namespaces/ns/workflows/wf-id%2F/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, { name: "valid event id missing", @@ -134,11 +134,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "eventType=WorkflowExecutionStarted&referenceType=EventReference", + RawQuery: "eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, - outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=WorkflowExecutionStarted&referenceType=EventReference", + outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference", }, } @@ -166,7 +166,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { URL: &url.URL{ Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -189,7 +189,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id>/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id%2E/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -212,7 +212,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id//run-id/history", RawPath: "/namespaces/ns/workflows/wf-id%2F/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -235,7 +235,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "referenceType=EventReference&eventID=&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -257,7 +257,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "random", Path: "/namespaces/ns/workflows/wf-id/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -270,7 +270,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/", RawPath: "/namespaces/ns/workflows/wf-id/run-id/", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -283,7 +283,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces//workflows/wf-id/run-id/history", RawPath: "/namespaces//workflows/wf-id/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", }, @@ -296,7 +296,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) { Scheme: "temporal", Path: "/namespaces/ns/workflows/wf-id/run-id/history", RawPath: "/namespaces/ns/workflows/wf-id/run-id/history", - RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecution", + RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_INVALID", }, Type: "temporal.api.common.v1.Link.WorkflowEvent", },