Skip to content

Commit

Permalink
Subscriptions: Add List.Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Jul 16, 2024
1 parent 38609a0 commit f45a386
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions exchanges/subscription/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func (l List) GroupPairs() (n List) {
return s.List()
}

// Clone returns a deep clone of the List
func (l List) Clone() List {
n := make(List, len(l))
for i, s := range l {
n[i] = s.Clone()
}
return n
}

// QualifiedChannels returns a sorted list of all the qualified Channels in the list
func (l List) QualifiedChannels() []string {
c := make([]string, len(l))
Expand Down
9 changes: 9 additions & 0 deletions exchanges/subscription/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ func TestAssetPairs(t *testing.T) {
assert.ErrorIs(t, err, expErr, "Should error correctly on GetPairFormat")
}
}

func TestListClone(t *testing.T) {
t.Parallel()
l := List{{Channel: TickerChannel}, {Channel: OrderbookChannel}}
n := l.Clone()
assert.NotSame(t, n, l, "Slices must not be the same")
require.NotEmpty(t, n, "List must not be empty")
assert.NotSame(t, n[0], l[0], "Subscriptions must be cloned")
}

0 comments on commit f45a386

Please sign in to comment.