Skip to content

Commit 9c4dde8

Browse files
authoredDec 4, 2024··
Use constant case in Nexus link URL eventType query param (#1741)
1 parent aa4535d commit 9c4dde8

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed
 

‎temporalnexus/link_converter.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var (
5959
rePatternWorkflowID,
6060
rePatternRunID,
6161
))
62+
eventReferenceType = string((&commonpb.Link_WorkflowEvent_EventReference{}).ProtoReflect().Descriptor().Name())
6263
)
6364

6465
// ConvertLinkWorkflowEventToNexusLink converts a Link_WorkflowEvent type to Nexus Link.
@@ -128,7 +129,7 @@ func ConvertNexusLinkToLinkWorkflowEvent(link nexus.Link) (*commonpb.Link_Workfl
128129
}
129130

130131
switch refType := link.URL.Query().Get(linkWorkflowEventReferenceTypeKey); refType {
131-
case string((&commonpb.Link_WorkflowEvent_EventReference{}).ProtoReflect().Descriptor().Name()):
132+
case eventReferenceType:
132133
eventRef, err := convertURLQueryToLinkWorkflowEventEventReference(link.URL.Query())
133134
if err != nil {
134135
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
148149

149150
func convertLinkWorkflowEventEventReferenceToURLQuery(eventRef *commonpb.Link_WorkflowEvent_EventReference) string {
150151
values := url.Values{}
151-
values.Set(linkWorkflowEventReferenceTypeKey, string(eventRef.ProtoReflect().Descriptor().Name()))
152+
values.Set(linkWorkflowEventReferenceTypeKey, eventReferenceType)
152153
if eventRef.GetEventId() > 0 {
153154
values.Set(linkEventReferenceEventIDKey, strconv.FormatInt(eventRef.GetEventId(), 10))
154155
}
155-
values.Set(linkEventReferenceEventTypeKey, eventRef.GetEventType().String())
156+
values.Set(linkEventReferenceEventTypeKey, enumspb.EventType_name[int32(eventRef.GetEventType())])
156157
return values.Encode()
157158
}
158159

‎temporalnexus/link_converter_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
6363
Scheme: "temporal",
6464
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
6565
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
66-
RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
66+
RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
6767
},
6868
Type: "temporal.api.common.v1.Link.WorkflowEvent",
6969
},
70-
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
70+
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
7171
},
7272
{
7373
name: "valid with angle bracket",
@@ -87,11 +87,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
8787
Scheme: "temporal",
8888
Path: "/namespaces/ns/workflows/wf-id>/run-id/history",
8989
RawPath: "/namespaces/ns/workflows/wf-id%3E/run-id/history",
90-
RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
90+
RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
9191
},
9292
Type: "temporal.api.common.v1.Link.WorkflowEvent",
9393
},
94-
outputURL: "temporal:///namespaces/ns/workflows/wf-id%3E/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
94+
outputURL: "temporal:///namespaces/ns/workflows/wf-id%3E/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
9595
},
9696
{
9797
name: "valid with slash",
@@ -111,11 +111,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
111111
Scheme: "temporal",
112112
Path: "/namespaces/ns/workflows/wf-id//run-id/history",
113113
RawPath: "/namespaces/ns/workflows/wf-id%2F/run-id/history",
114-
RawQuery: "eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
114+
RawQuery: "eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
115115
},
116116
Type: "temporal.api.common.v1.Link.WorkflowEvent",
117117
},
118-
outputURL: "temporal:///namespaces/ns/workflows/wf-id%2F/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference",
118+
outputURL: "temporal:///namespaces/ns/workflows/wf-id%2F/run-id/history?eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
119119
},
120120
{
121121
name: "valid event id missing",
@@ -134,11 +134,11 @@ func TestConvertLinkWorkflowEventToNexusLink(t *testing.T) {
134134
Scheme: "temporal",
135135
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
136136
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
137-
RawQuery: "eventType=WorkflowExecutionStarted&referenceType=EventReference",
137+
RawQuery: "eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
138138
},
139139
Type: "temporal.api.common.v1.Link.WorkflowEvent",
140140
},
141-
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=WorkflowExecutionStarted&referenceType=EventReference",
141+
outputURL: "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED&referenceType=EventReference",
142142
},
143143
}
144144

@@ -166,7 +166,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
166166
URL: &url.URL{
167167
Scheme: "temporal",
168168
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
169-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
169+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
170170
},
171171
Type: "temporal.api.common.v1.Link.WorkflowEvent",
172172
},
@@ -189,7 +189,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
189189
Scheme: "temporal",
190190
Path: "/namespaces/ns/workflows/wf-id>/run-id/history",
191191
RawPath: "/namespaces/ns/workflows/wf-id%2E/run-id/history",
192-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
192+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
193193
},
194194
Type: "temporal.api.common.v1.Link.WorkflowEvent",
195195
},
@@ -212,7 +212,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
212212
Scheme: "temporal",
213213
Path: "/namespaces/ns/workflows/wf-id//run-id/history",
214214
RawPath: "/namespaces/ns/workflows/wf-id%2F/run-id/history",
215-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
215+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
216216
},
217217
Type: "temporal.api.common.v1.Link.WorkflowEvent",
218218
},
@@ -235,7 +235,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
235235
Scheme: "temporal",
236236
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
237237
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
238-
RawQuery: "referenceType=EventReference&eventID=&eventType=WorkflowExecutionStarted",
238+
RawQuery: "referenceType=EventReference&eventID=&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
239239
},
240240
Type: "temporal.api.common.v1.Link.WorkflowEvent",
241241
},
@@ -257,7 +257,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
257257
Scheme: "random",
258258
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
259259
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
260-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
260+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
261261
},
262262
Type: "temporal.api.common.v1.Link.WorkflowEvent",
263263
},
@@ -270,7 +270,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
270270
Scheme: "temporal",
271271
Path: "/namespaces/ns/workflows/wf-id/run-id/",
272272
RawPath: "/namespaces/ns/workflows/wf-id/run-id/",
273-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
273+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
274274
},
275275
Type: "temporal.api.common.v1.Link.WorkflowEvent",
276276
},
@@ -283,7 +283,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
283283
Scheme: "temporal",
284284
Path: "/namespaces//workflows/wf-id/run-id/history",
285285
RawPath: "/namespaces//workflows/wf-id/run-id/history",
286-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecutionStarted",
286+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",
287287
},
288288
Type: "temporal.api.common.v1.Link.WorkflowEvent",
289289
},
@@ -296,7 +296,7 @@ func TestConvertNexusLinkToLinkWorkflowEvent(t *testing.T) {
296296
Scheme: "temporal",
297297
Path: "/namespaces/ns/workflows/wf-id/run-id/history",
298298
RawPath: "/namespaces/ns/workflows/wf-id/run-id/history",
299-
RawQuery: "referenceType=EventReference&eventID=1&eventType=WorkflowExecution",
299+
RawQuery: "referenceType=EventReference&eventID=1&eventType=EVENT_TYPE_INVALID",
300300
},
301301
Type: "temporal.api.common.v1.Link.WorkflowEvent",
302302
},

0 commit comments

Comments
 (0)
Please sign in to comment.