Skip to content

Commit

Permalink
Add abiliy to add comments to exepcted history in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin committed Jun 1, 2023
1 parent 10a14e3 commit 00db241
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
51 changes: 49 additions & 2 deletions tests/integrationbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,59 @@ func (s *IntegrationBase) formatHistoryCompact(history *historypb.History) strin

func (s *IntegrationBase) EqualHistory(expectedHistory string, actualHistory *historypb.History) {
s.T().Helper()
expectedHistoryTrimmed := strings.Trim(expectedHistory, "\n")
expectedHistorySanitized := s.sanitizeHistory(expectedHistory)
actualHistoryStr := s.formatHistoryCompact(actualHistory)
s.Equal(expectedHistoryTrimmed, actualHistoryStr)
s.Equal(expectedHistorySanitized, actualHistoryStr)
}

func (s *IntegrationBase) EqualHistoryEvents(expectedHistory string, actualHistoryEvents []*historypb.HistoryEvent) {
s.T().Helper()
s.EqualHistory(expectedHistory, &historypb.History{Events: actualHistoryEvents})
}

// sanitizeHistory removes all empty new lines and comments from expectedHistory string.
func (s *IntegrationBase) sanitizeHistory(expectedHistory string) string {
type state int
const (
stateStart state = iota
stateNormal
stateComment
stateNewLine
)

var ret strings.Builder
st := stateStart
spaceCounter := 0
for _, r := range expectedHistory {
switch r {
case '\n':
if st == stateStart {
continue
}
spaceCounter = 0
st = stateNewLine
case '/':
spaceCounter = 0
st = stateComment
case ' ':
if st == stateComment {
continue
}
spaceCounter++
default:
if st == stateComment {
continue
}
if st == stateNewLine {
ret.WriteRune('\n')
}
if spaceCounter > 0 {
ret.WriteString(strings.Repeat(" ", spaceCounter))
spaceCounter = 0
}
ret.WriteRune(r)
st = stateNormal
}
}
return ret.String()
}
5 changes: 3 additions & 2 deletions tests/update_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,16 @@ func (s *integrationSuite) TestUpdateWorkflow_NewSpeculativeWorkflowTask_AcceptC
3 WorkflowTaskStarted
4 WorkflowTaskCompleted
5 ActivityTaskScheduled
6 WorkflowTaskScheduled
6 WorkflowTaskScheduled // Was speculative WT but was converted to normal WT.
7 WorkflowTaskStarted
8 WorkflowTaskCompleted
9 WorkflowExecutionUpdateAccepted
10 WorkflowExecutionUpdateCompleted
11 WorkflowTaskScheduled
12 WorkflowTaskStarted
13 WorkflowTaskCompleted
14 WorkflowExecutionCompleted`, events)
14 WorkflowExecutionCompleted
`, events)
})
}
}
Expand Down

0 comments on commit 00db241

Please sign in to comment.