mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 15:09:59 +00:00
Subscriptions: Fix subscription.Clone Params and Pairs (#1582)
* Subscriptions: Fix subscription.Clone Params and Pairs * fixup! Subscriptions: Fix subscription.Clone Params and Pairs
This commit is contained in:
@@ -132,16 +132,14 @@ func (s *Subscription) Clone() *Subscription {
|
||||
Enabled: s.Enabled,
|
||||
Channel: s.Channel,
|
||||
Asset: s.Asset,
|
||||
Params: s.Params,
|
||||
Params: maps.Clone(s.Params),
|
||||
Interval: s.Interval,
|
||||
Levels: s.Levels,
|
||||
Authenticated: s.Authenticated,
|
||||
state: s.state,
|
||||
Pairs: s.Pairs,
|
||||
Pairs: slices.Clone(s.Pairs),
|
||||
QualifiedChannel: s.QualifiedChannel,
|
||||
}
|
||||
s.Pairs = slices.Clone(s.Pairs)
|
||||
s.Params = maps.Clone(s.Params)
|
||||
s.m.RUnlock()
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -93,21 +93,24 @@ func TestSubscriptionMarshaling(t *testing.T) {
|
||||
// TestClone exercises Clone
|
||||
func TestClone(t *testing.T) {
|
||||
t.Parallel()
|
||||
params := map[string]any{"a": 42}
|
||||
a := &Subscription{
|
||||
Channel: TickerChannel,
|
||||
Interval: kline.OneHour,
|
||||
Pairs: currency.Pairs{btcusdtPair},
|
||||
Params: map[string]any{"a": 42},
|
||||
Params: params,
|
||||
}
|
||||
a.EnsureKeyed()
|
||||
b := a.Clone()
|
||||
assert.IsType(t, new(Subscription), b, "Clone must return a Subscription pointer")
|
||||
assert.NotSame(t, a, b, "Clone should return a new Subscription")
|
||||
assert.Nil(t, b.Key, "Clone should have a nil key")
|
||||
b.Pairs[0] = ethusdcPair
|
||||
assert.Equal(t, btcusdtPair, a.Pairs[0], "Pairs should be (relatively) deep copied")
|
||||
b.Pairs[0].Delimiter = "🐳"
|
||||
assert.Empty(t, a.Pairs[0].Delimiter, "Pairs should be (relatively) deep copied")
|
||||
b.Params["a"] = 12
|
||||
assert.Equal(t, 42, a.Params["a"], "Params should be (relatively) deep copied")
|
||||
assert.NotEqual(t, params, b.Params, "Params should be cloned")
|
||||
assert.Equal(t, params, a.Params, "Original Params should be left alone")
|
||||
a.m.Lock()
|
||||
assert.True(t, b.m.TryLock(), "Clone must use a different Mutex")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user