Skip to content

Commit

Permalink
Bybit: Test Subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Aug 2, 2024
1 parent 948c9ca commit 5ad0f4e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions exchanges/bybit/bybit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
Expand All @@ -23,8 +24,10 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
testsubs "github.com/thrasher-corp/gocryptotrader/internal/testing/subscriptions"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)

Expand Down Expand Up @@ -3578,3 +3581,54 @@ func TestGetCurrencyTradeURL(t *testing.T) {
assert.NotEmpty(t, resp)
}
}

// TestGenerateSubscriptions exercises generateSubscriptions
func TestGenerateSubscriptions(t *testing.T) {
t.Parallel()

b := new(Bybit) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes

Check failure on line 3589 in exchanges/bybit/bybit_test.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:govet // Intentional shadow to avoid future copy/paste mistakes` is unused for linter "govet" (nolintlint)
require.NoError(t, testexch.Setup(b), "Test instance Setup must not error")

b.Websocket.SetCanUseAuthenticatedEndpoints(true)
subs, err := b.generateSubscriptions()
require.NoError(t, err, "generateSubscriptions must not error")
exp := subscription.List{}
for _, s := range b.Features.Subscriptions {
for _, a := range b.GetAssetTypes(true) {
if s.Asset != asset.All && s.Asset != a {
continue
}
pairs, err := b.GetEnabledPairs(a)
require.NoErrorf(t, err, "GetEnabledPairs %s must not error", a)
pairs = common.SortStrings(pairs).Format(currency.PairFormat{Uppercase: true, Delimiter: "_"})
s := s.Clone() //nolint:govet // Intentional lexical scope shadow
s.Asset = a
if isSymbolChannel(channelName(s)) {
for i := range pairs {
s := s.Clone() //nolint:govet // Intentional lexical scope shadow
switch s.Channel {

Check failure on line 3609 in exchanges/bybit/bybit_test.go

View workflow job for this annotation

GitHub Actions / lint

empty-block: this block is empty, you can remove it (revive)
}
s.Pairs = pairs[i : i+1]
exp = append(exp, s)
}
} else {
s.Pairs = pairs
s.QualifiedChannel = pairs.Join()
exp = append(exp, s)
}
}
}
testsubs.EqualLists(t, exp, subs)
}

func TestSubscribe(t *testing.T) {
t.Parallel()
b := new(Bybit) //nolint:govet // Intentional shadow to avoid future copy/paste mistakes

Check failure on line 3626 in exchanges/bybit/bybit_test.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:govet // Intentional shadow to avoid future copy/paste mistakes` is unused for linter "govet" (nolintlint)
require.NoError(t, testexch.Setup(b), "Test instance Setup must not error")
subs, err := b.Features.Subscriptions.ExpandTemplates(b)
require.NoError(t, err, "ExpandTemplates must not error")
b.Features.Subscriptions = subscription.List{}
testexch.SetupWs(t, b)
err = b.Subscribe(subs)
require.NoError(t, err, "Subscribe must not error")
}

0 comments on commit 5ad0f4e

Please sign in to comment.