Skip to content

Commit

Permalink
Use constant case in Nexus link URL eventType query param (#1741)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergundy authored Dec 4, 2024
1 parent aa4535d commit 9c4dde8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
7 changes: 4 additions & 3 deletions temporalnexus/link_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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()
}

Expand Down
32 changes: 16 additions & 16 deletions temporalnexus/link_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
},
}

Expand Down Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand Down

0 comments on commit 9c4dde8

Please sign in to comment.