Skip to content

Commit

Permalink
Merge pull request #164 from overmindtech/fix-copy-include-tags
Browse files Browse the repository at this point in the history
Added tags to copied item
  • Loading branch information
dylanratcliffe authored Oct 31, 2023
2 parents 3edbba5 + 17dc63a commit 4b01e46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions items.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ func (i *Item) Copy(dest *Item) {
} else {
dest.Health = i.Health.Enum()
}

if i.Tags != nil {
dest.Tags = make(map[string]string)

for k, v := range i.Tags {
dest.Tags[k] = v
}
}
}

// Hash Returns a 12 character hash for the item. This is likely but not
Expand Down
9 changes: 9 additions & 0 deletions items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func TestCopy(t *testing.T) {
SourceDurationPerItem: durationpb.New(10 * time.Millisecond),
},
Health: Health_HEALTH_ERROR.Enum(),
Tags: map[string]string{
"foo": "bar",
},
}

itemB := Item{}
Expand Down Expand Up @@ -373,6 +376,12 @@ func AssertItemsEqual(itemA *Item, itemB *Item, t *testing.T) {
}
}

for k, v := range itemA.Tags {
if itemB.Tags[k] != v {
t.Errorf("Tags[%v] did not match", k)
}
}

if itemA.Health == nil {
if itemB.Health != nil {
t.Errorf("mismatched health nil and %v", *itemB.Health)
Expand Down

0 comments on commit 4b01e46

Please sign in to comment.