@@ -24,7 +24,11 @@ import (
2424 "reflect"
2525 "testing"
2626
27+ "github.com/stretchr/testify/assert"
2728 "github.com/stretchr/testify/require"
29+ "go.uber.org/thriftrw/ptr"
30+
31+ s "go.uber.org/cadence/.gen/go/shared"
2832)
2933
3034func Test_anyToString (t * testing.T ) {
@@ -114,3 +118,209 @@ func Test_byteSliceToString(t *testing.T) {
114118
115119 require .Equal (t , "[len=3]" , strVal2 )
116120}
121+
122+ func TestHistoryEventToString (t * testing.T ) {
123+ event := & s.HistoryEvent {
124+ EventType : toPtr (s .EventTypeWorkflowExecutionStarted ),
125+ WorkflowExecutionStartedEventAttributes : & s.WorkflowExecutionStartedEventAttributes {
126+ WorkflowType : & s.WorkflowType {
127+ Name : toPtr ("test-workflow" ),
128+ },
129+ TaskList : & s.TaskList {
130+ Name : toPtr ("task-list" ),
131+ },
132+ ExecutionStartToCloseTimeoutSeconds : ptr .Int32 (60 ),
133+ },
134+ }
135+
136+ strVal := HistoryEventToString (event )
137+
138+ expected := `WorkflowExecutionStarted: (WorkflowType:(Name:test-workflow), TaskList:(Name:task-list), Input:[], ExecutionStartToCloseTimeoutSeconds:60, ContinuedFailureDetails:[], LastCompletionResult:[], PartitionConfig:map[])`
139+
140+ assert .Equal (t , expected , strVal )
141+ }
142+
143+ // This just tests that we pick the right attibutes to return
144+ // the other attributes will be nil
145+ func Test_getData (t * testing.T ) {
146+ cases := []struct {
147+ event * s.HistoryEvent
148+ expected interface {}
149+ }{
150+ {
151+ event : & s.HistoryEvent {
152+ EventType : toPtr (s .EventTypeWorkflowExecutionStarted ),
153+ WorkflowExecutionStartedEventAttributes : & s.WorkflowExecutionStartedEventAttributes {},
154+ },
155+ expected : & s.WorkflowExecutionStartedEventAttributes {},
156+ },
157+ {
158+ event : & s.HistoryEvent {
159+ EventType : toPtr (s .EventTypeWorkflowExecutionCompleted ),
160+ WorkflowExecutionCompletedEventAttributes : & s.WorkflowExecutionCompletedEventAttributes {},
161+ },
162+ expected : & s.WorkflowExecutionCompletedEventAttributes {},
163+ },
164+ {
165+ event : & s.HistoryEvent {
166+ EventType : toPtr (s .EventTypeWorkflowExecutionFailed ),
167+ WorkflowExecutionFailedEventAttributes : & s.WorkflowExecutionFailedEventAttributes {},
168+ },
169+ expected : & s.WorkflowExecutionFailedEventAttributes {},
170+ },
171+ {
172+ event : & s.HistoryEvent {
173+ EventType : toPtr (s .EventTypeWorkflowExecutionTimedOut ),
174+ WorkflowExecutionTimedOutEventAttributes : & s.WorkflowExecutionTimedOutEventAttributes {},
175+ },
176+ expected : & s.WorkflowExecutionTimedOutEventAttributes {},
177+ },
178+ {
179+ event : & s.HistoryEvent {
180+ EventType : toPtr (s .EventTypeDecisionTaskScheduled ),
181+ DecisionTaskScheduledEventAttributes : & s.DecisionTaskScheduledEventAttributes {},
182+ },
183+ expected : & s.DecisionTaskScheduledEventAttributes {},
184+ },
185+ {
186+ event : & s.HistoryEvent {
187+ EventType : toPtr (s .EventTypeDecisionTaskStarted ),
188+ DecisionTaskStartedEventAttributes : & s.DecisionTaskStartedEventAttributes {},
189+ },
190+ expected : & s.DecisionTaskStartedEventAttributes {},
191+ },
192+ {
193+ event : & s.HistoryEvent {
194+ EventType : toPtr (s .EventTypeDecisionTaskCompleted ),
195+ DecisionTaskCompletedEventAttributes : & s.DecisionTaskCompletedEventAttributes {},
196+ },
197+ expected : & s.DecisionTaskCompletedEventAttributes {},
198+ },
199+ {
200+ event : & s.HistoryEvent {
201+ EventType : toPtr (s .EventTypeDecisionTaskTimedOut ),
202+ DecisionTaskTimedOutEventAttributes : & s.DecisionTaskTimedOutEventAttributes {},
203+ },
204+ expected : & s.DecisionTaskTimedOutEventAttributes {},
205+ },
206+ {
207+ event : & s.HistoryEvent {
208+ EventType : toPtr (s .EventTypeActivityTaskScheduled ),
209+ ActivityTaskScheduledEventAttributes : & s.ActivityTaskScheduledEventAttributes {},
210+ },
211+ expected : & s.ActivityTaskScheduledEventAttributes {},
212+ },
213+ {
214+ event : & s.HistoryEvent {
215+ EventType : toPtr (s .EventTypeActivityTaskStarted ),
216+ ActivityTaskStartedEventAttributes : & s.ActivityTaskStartedEventAttributes {},
217+ },
218+ expected : & s.ActivityTaskStartedEventAttributes {},
219+ },
220+ {
221+ event : & s.HistoryEvent {
222+ EventType : toPtr (s .EventTypeActivityTaskCompleted ),
223+ ActivityTaskCompletedEventAttributes : & s.ActivityTaskCompletedEventAttributes {},
224+ },
225+ expected : & s.ActivityTaskCompletedEventAttributes {},
226+ },
227+ {
228+ event : & s.HistoryEvent {
229+ EventType : toPtr (s .EventTypeActivityTaskFailed ),
230+ ActivityTaskFailedEventAttributes : & s.ActivityTaskFailedEventAttributes {},
231+ },
232+ expected : & s.ActivityTaskFailedEventAttributes {},
233+ },
234+ {
235+ event : & s.HistoryEvent {
236+ EventType : toPtr (s .EventTypeActivityTaskTimedOut ),
237+ ActivityTaskTimedOutEventAttributes : & s.ActivityTaskTimedOutEventAttributes {},
238+ },
239+ expected : & s.ActivityTaskTimedOutEventAttributes {},
240+ },
241+ {
242+ event : & s.HistoryEvent {
243+ EventType : toPtr (s .EventTypeActivityTaskCancelRequested ),
244+ ActivityTaskCancelRequestedEventAttributes : & s.ActivityTaskCancelRequestedEventAttributes {},
245+ },
246+ expected : & s.ActivityTaskCancelRequestedEventAttributes {},
247+ },
248+ {
249+ event : & s.HistoryEvent {
250+ EventType : toPtr (s .EventTypeRequestCancelActivityTaskFailed ),
251+ RequestCancelActivityTaskFailedEventAttributes : & s.RequestCancelActivityTaskFailedEventAttributes {},
252+ },
253+ expected : & s.RequestCancelActivityTaskFailedEventAttributes {},
254+ },
255+ {
256+ event : & s.HistoryEvent {
257+ EventType : toPtr (s .EventTypeActivityTaskCanceled ),
258+ ActivityTaskCanceledEventAttributes : & s.ActivityTaskCanceledEventAttributes {},
259+ },
260+ expected : & s.ActivityTaskCanceledEventAttributes {},
261+ },
262+ {
263+ event : & s.HistoryEvent {
264+ EventType : toPtr (s .EventTypeTimerStarted ),
265+ TimerStartedEventAttributes : & s.TimerStartedEventAttributes {},
266+ },
267+ expected : & s.TimerStartedEventAttributes {},
268+ },
269+ {
270+ event : & s.HistoryEvent {
271+ EventType : toPtr (s .EventTypeTimerFired ),
272+ TimerFiredEventAttributes : & s.TimerFiredEventAttributes {},
273+ },
274+ expected : & s.TimerFiredEventAttributes {},
275+ },
276+ {
277+ event : & s.HistoryEvent {
278+ EventType : toPtr (s .EventTypeCancelTimerFailed ),
279+ CancelTimerFailedEventAttributes : & s.CancelTimerFailedEventAttributes {},
280+ },
281+ expected : & s.CancelTimerFailedEventAttributes {},
282+ },
283+ {
284+ event : & s.HistoryEvent {
285+ EventType : toPtr (s .EventTypeTimerCanceled ),
286+ TimerCanceledEventAttributes : & s.TimerCanceledEventAttributes {},
287+ },
288+ expected : & s.TimerCanceledEventAttributes {},
289+ },
290+ {
291+ event : & s.HistoryEvent {
292+ EventType : toPtr (s .EventTypeMarkerRecorded ),
293+ MarkerRecordedEventAttributes : & s.MarkerRecordedEventAttributes {},
294+ },
295+ expected : & s.MarkerRecordedEventAttributes {},
296+ },
297+ {
298+ event : & s.HistoryEvent {
299+ EventType : toPtr (s .EventTypeWorkflowExecutionTerminated ),
300+ WorkflowExecutionTerminatedEventAttributes : & s.WorkflowExecutionTerminatedEventAttributes {},
301+ },
302+ expected : & s.WorkflowExecutionTerminatedEventAttributes {},
303+ },
304+ // In the default case, we should return the event itself
305+ {
306+ event : & s.HistoryEvent {
307+ EventType : toPtr (s .EventType (123456789 )),
308+ },
309+ expected : & s.HistoryEvent {
310+ EventType : toPtr (s .EventType (123456789 )),
311+ },
312+ },
313+ }
314+
315+ for _ , tc := range cases {
316+ name , err := tc .event .GetEventType ().MarshalText ()
317+ require .NoError (t , err )
318+ t .Run (string (name ), func (t * testing.T ) {
319+ require .Equal (t , tc .expected , getData (tc .event ))
320+ })
321+ }
322+ }
323+
324+ func toPtr [v any ](x v ) * v {
325+ return & x
326+ }
0 commit comments