@@ -24,7 +24,10 @@ import (
2424 "reflect"
2525 "testing"
2626
27+ "github.com/stretchr/testify/assert"
2728 "github.com/stretchr/testify/require"
29+ s "go.uber.org/cadence/.gen/go/shared"
30+ "go.uber.org/thriftrw/ptr"
2831)
2932
3033func Test_byteSliceToString (t * testing.T ) {
@@ -40,3 +43,209 @@ func Test_byteSliceToString(t *testing.T) {
4043
4144 require .Equal (t , "[len=3]" , strVal2 )
4245}
46+
47+ func TestHistoryEventToString (t * testing.T ) {
48+ event := & s.HistoryEvent {
49+ EventType : toPtr (s .EventTypeWorkflowExecutionStarted ),
50+ WorkflowExecutionStartedEventAttributes : & s.WorkflowExecutionStartedEventAttributes {
51+ WorkflowType : & s.WorkflowType {
52+ Name : toPtr ("test-workflow" ),
53+ },
54+ TaskList : & s.TaskList {
55+ Name : toPtr ("task-list" ),
56+ },
57+ ExecutionStartToCloseTimeoutSeconds : ptr .Int32 (60 ),
58+ },
59+ }
60+
61+ strVal := HistoryEventToString (event )
62+
63+ expected := `WorkflowExecutionStarted: (WorkflowType:(Name:test-workflow), TaskList:(Name:task-list), Input:[], ExecutionStartToCloseTimeoutSeconds:60, ContinuedFailureDetails:[], LastCompletionResult:[], PartitionConfig:map[])`
64+
65+ assert .Equal (t , expected , strVal )
66+ }
67+
68+ // This just tests that we pick the right attibutes to return
69+ // the other attributes will be nil
70+ func Test_getData (t * testing.T ) {
71+ cases := []struct {
72+ event * s.HistoryEvent
73+ expected interface {}
74+ }{
75+ {
76+ event : & s.HistoryEvent {
77+ EventType : toPtr (s .EventTypeWorkflowExecutionStarted ),
78+ WorkflowExecutionStartedEventAttributes : & s.WorkflowExecutionStartedEventAttributes {},
79+ },
80+ expected : & s.WorkflowExecutionStartedEventAttributes {},
81+ },
82+ {
83+ event : & s.HistoryEvent {
84+ EventType : toPtr (s .EventTypeWorkflowExecutionCompleted ),
85+ WorkflowExecutionCompletedEventAttributes : & s.WorkflowExecutionCompletedEventAttributes {},
86+ },
87+ expected : & s.WorkflowExecutionCompletedEventAttributes {},
88+ },
89+ {
90+ event : & s.HistoryEvent {
91+ EventType : toPtr (s .EventTypeWorkflowExecutionFailed ),
92+ WorkflowExecutionFailedEventAttributes : & s.WorkflowExecutionFailedEventAttributes {},
93+ },
94+ expected : & s.WorkflowExecutionFailedEventAttributes {},
95+ },
96+ {
97+ event : & s.HistoryEvent {
98+ EventType : toPtr (s .EventTypeWorkflowExecutionTimedOut ),
99+ WorkflowExecutionTimedOutEventAttributes : & s.WorkflowExecutionTimedOutEventAttributes {},
100+ },
101+ expected : & s.WorkflowExecutionTimedOutEventAttributes {},
102+ },
103+ {
104+ event : & s.HistoryEvent {
105+ EventType : toPtr (s .EventTypeDecisionTaskScheduled ),
106+ DecisionTaskScheduledEventAttributes : & s.DecisionTaskScheduledEventAttributes {},
107+ },
108+ expected : & s.DecisionTaskScheduledEventAttributes {},
109+ },
110+ {
111+ event : & s.HistoryEvent {
112+ EventType : toPtr (s .EventTypeDecisionTaskStarted ),
113+ DecisionTaskStartedEventAttributes : & s.DecisionTaskStartedEventAttributes {},
114+ },
115+ expected : & s.DecisionTaskStartedEventAttributes {},
116+ },
117+ {
118+ event : & s.HistoryEvent {
119+ EventType : toPtr (s .EventTypeDecisionTaskCompleted ),
120+ DecisionTaskCompletedEventAttributes : & s.DecisionTaskCompletedEventAttributes {},
121+ },
122+ expected : & s.DecisionTaskCompletedEventAttributes {},
123+ },
124+ {
125+ event : & s.HistoryEvent {
126+ EventType : toPtr (s .EventTypeDecisionTaskTimedOut ),
127+ DecisionTaskTimedOutEventAttributes : & s.DecisionTaskTimedOutEventAttributes {},
128+ },
129+ expected : & s.DecisionTaskTimedOutEventAttributes {},
130+ },
131+ {
132+ event : & s.HistoryEvent {
133+ EventType : toPtr (s .EventTypeActivityTaskScheduled ),
134+ ActivityTaskScheduledEventAttributes : & s.ActivityTaskScheduledEventAttributes {},
135+ },
136+ expected : & s.ActivityTaskScheduledEventAttributes {},
137+ },
138+ {
139+ event : & s.HistoryEvent {
140+ EventType : toPtr (s .EventTypeActivityTaskStarted ),
141+ ActivityTaskStartedEventAttributes : & s.ActivityTaskStartedEventAttributes {},
142+ },
143+ expected : & s.ActivityTaskStartedEventAttributes {},
144+ },
145+ {
146+ event : & s.HistoryEvent {
147+ EventType : toPtr (s .EventTypeActivityTaskCompleted ),
148+ ActivityTaskCompletedEventAttributes : & s.ActivityTaskCompletedEventAttributes {},
149+ },
150+ expected : & s.ActivityTaskCompletedEventAttributes {},
151+ },
152+ {
153+ event : & s.HistoryEvent {
154+ EventType : toPtr (s .EventTypeActivityTaskFailed ),
155+ ActivityTaskFailedEventAttributes : & s.ActivityTaskFailedEventAttributes {},
156+ },
157+ expected : & s.ActivityTaskFailedEventAttributes {},
158+ },
159+ {
160+ event : & s.HistoryEvent {
161+ EventType : toPtr (s .EventTypeActivityTaskTimedOut ),
162+ ActivityTaskTimedOutEventAttributes : & s.ActivityTaskTimedOutEventAttributes {},
163+ },
164+ expected : & s.ActivityTaskTimedOutEventAttributes {},
165+ },
166+ {
167+ event : & s.HistoryEvent {
168+ EventType : toPtr (s .EventTypeActivityTaskCancelRequested ),
169+ ActivityTaskCancelRequestedEventAttributes : & s.ActivityTaskCancelRequestedEventAttributes {},
170+ },
171+ expected : & s.ActivityTaskCancelRequestedEventAttributes {},
172+ },
173+ {
174+ event : & s.HistoryEvent {
175+ EventType : toPtr (s .EventTypeRequestCancelActivityTaskFailed ),
176+ RequestCancelActivityTaskFailedEventAttributes : & s.RequestCancelActivityTaskFailedEventAttributes {},
177+ },
178+ expected : & s.RequestCancelActivityTaskFailedEventAttributes {},
179+ },
180+ {
181+ event : & s.HistoryEvent {
182+ EventType : toPtr (s .EventTypeActivityTaskCanceled ),
183+ ActivityTaskCanceledEventAttributes : & s.ActivityTaskCanceledEventAttributes {},
184+ },
185+ expected : & s.ActivityTaskCanceledEventAttributes {},
186+ },
187+ {
188+ event : & s.HistoryEvent {
189+ EventType : toPtr (s .EventTypeTimerStarted ),
190+ TimerStartedEventAttributes : & s.TimerStartedEventAttributes {},
191+ },
192+ expected : & s.TimerStartedEventAttributes {},
193+ },
194+ {
195+ event : & s.HistoryEvent {
196+ EventType : toPtr (s .EventTypeTimerFired ),
197+ TimerFiredEventAttributes : & s.TimerFiredEventAttributes {},
198+ },
199+ expected : & s.TimerFiredEventAttributes {},
200+ },
201+ {
202+ event : & s.HistoryEvent {
203+ EventType : toPtr (s .EventTypeCancelTimerFailed ),
204+ CancelTimerFailedEventAttributes : & s.CancelTimerFailedEventAttributes {},
205+ },
206+ expected : & s.CancelTimerFailedEventAttributes {},
207+ },
208+ {
209+ event : & s.HistoryEvent {
210+ EventType : toPtr (s .EventTypeTimerCanceled ),
211+ TimerCanceledEventAttributes : & s.TimerCanceledEventAttributes {},
212+ },
213+ expected : & s.TimerCanceledEventAttributes {},
214+ },
215+ {
216+ event : & s.HistoryEvent {
217+ EventType : toPtr (s .EventTypeMarkerRecorded ),
218+ MarkerRecordedEventAttributes : & s.MarkerRecordedEventAttributes {},
219+ },
220+ expected : & s.MarkerRecordedEventAttributes {},
221+ },
222+ {
223+ event : & s.HistoryEvent {
224+ EventType : toPtr (s .EventTypeWorkflowExecutionTerminated ),
225+ WorkflowExecutionTerminatedEventAttributes : & s.WorkflowExecutionTerminatedEventAttributes {},
226+ },
227+ expected : & s.WorkflowExecutionTerminatedEventAttributes {},
228+ },
229+ // In the default case, we should return the event itself
230+ {
231+ event : & s.HistoryEvent {
232+ EventType : toPtr (s .EventType (123456789 )),
233+ },
234+ expected : & s.HistoryEvent {
235+ EventType : toPtr (s .EventType (123456789 )),
236+ },
237+ },
238+ }
239+
240+ for _ , tc := range cases {
241+ name , err := tc .event .GetEventType ().MarshalText ()
242+ require .NoError (t , err )
243+ t .Run (string (name ), func (t * testing.T ) {
244+ require .Equal (t , tc .expected , getData (tc .event ))
245+ })
246+ }
247+ }
248+
249+ func toPtr [v any ](x v ) * v {
250+ return & x
251+ }
0 commit comments