Skip to content

Commit

Permalink
fixup! Bybit: Subscription configuration for spot
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Oct 17, 2024
1 parent 2de0fb2 commit c5e1633
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions exchanges/bybit/bybit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/gofrs/uuid"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common"
Expand Down Expand Up @@ -3744,3 +3745,34 @@ func TestSubscribe(t *testing.T) {
err = b.Subscribe(subs)
require.NoError(t, err, "Subscribe must not error")
}

func TestAuthSubcribe(t *testing.T) {
t.Parallel()
b := new(Bybit)
require.NoError(t, testexch.Setup(b), "Test instance Setup must not error")
b.Websocket.SetCanUseAuthenticatedEndpoints(true)
subs, err := b.Features.Subscriptions.ExpandTemplates(b)
require.NoError(t, err, "ExpandTemplates must not error")
b.Features.Subscriptions = subscription.List{}
success := true
mock := func(msg []byte, w *websocket.Conn) error {
var req SubscriptionArgument
require.NoError(t, json.Unmarshal(msg, &req), "Unmarshal must not error")
require.Equal(t, "subscribe", req.Operation)
msg, err = json.Marshal(SubscriptionResponse{
Success: success,
RetMsg: "Mock Resp Error",
RequestID: req.RequestID,
Operation: req.Operation,
})
require.NoError(t, err, "Marshal must not error")
return w.WriteMessage(websocket.TextMessage, msg)
}
b = testexch.MockWsInstance[Bybit](t, testexch.CurryWsMockUpgrader(t, mock))
b.Websocket.AuthConn = b.Websocket.Conn
err = b.Subscribe(subs)
require.NoError(t, err, "Subscribe must not error")
success = false
err = b.Subscribe(subs)
assert.ErrorContains(t, err, "Mock Resp Error", "Subscribe should error containing the returned RetMsg")
}

0 comments on commit c5e1633

Please sign in to comment.