Skip to content

Commit

Permalink
Fix mapping (#6531)
Browse files Browse the repository at this point in the history
* Fix mapping
  • Loading branch information
davidporter-id-au authored Dec 3, 2024
1 parent 5f579dd commit 5d60abd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 7 additions & 9 deletions common/persistence/versionHistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ func NewVersionHistoryItem(
func NewVersionHistoryItemFromInternalType(
input *types.VersionHistoryItem,
) *VersionHistoryItem {

if input == nil {
panic("version history item is null")
return nil
}

return NewVersionHistoryItem(input.EventID, input.Version)
}

Expand Down Expand Up @@ -107,7 +105,7 @@ func NewVersionHistoryFromInternalType(
) *VersionHistory {

if input == nil {
panic("version history is null")
return nil
}

items := make([]*VersionHistoryItem, 0, len(input.Items))
Expand All @@ -125,6 +123,9 @@ func (v *VersionHistory) Duplicate() *VersionHistory {

// ToInternalType return internal format of version history
func (v *VersionHistory) ToInternalType() *types.VersionHistory {
if v == nil {
return nil
}

token := make([]byte, len(v.BranchToken))
copy(token, v.BranchToken)
Expand Down Expand Up @@ -363,11 +364,9 @@ func (v *VersionHistory) Equals(
func NewVersionHistories(
versionHistory *VersionHistory,
) *VersionHistories {

if versionHistory == nil {
panic("version history cannot be null")
return nil
}

return &VersionHistories{
CurrentVersionHistoryIndex: 0,
Histories: []*VersionHistory{versionHistory},
Expand All @@ -378,9 +377,8 @@ func NewVersionHistories(
func NewVersionHistoriesFromInternalType(
input *types.VersionHistories,
) *VersionHistories {

if input == nil {
panic("version histories is null")
return nil
}
if len(input.Histories) == 0 {
panic("version histories cannot have empty")
Expand Down
10 changes: 10 additions & 0 deletions common/persistence/versionHistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package persistence
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"

"github.com/uber/cadence/common"
Expand Down Expand Up @@ -703,3 +704,12 @@ func (s *versionHistoriesSuite) TestCurrentVersionHistoryIndexIsInReplay() {
s.NoError(err)
s.False(isInReplay)
}

func TestNilHandling(t *testing.T) {
assert.Nil(t, NewVersionHistoriesFromInternalType(nil))
assert.Nil(t, NewVersionHistories(nil))
assert.Nil(t, NewVersionHistoryItemFromInternalType(nil))
assert.Nil(t, NewVersionHistoryFromInternalType(nil))
var vh *VersionHistory
assert.Nil(t, vh.ToInternalType())
}

0 comments on commit 5d60abd

Please sign in to comment.