fix(monitor/collectors/coinbase): exhaustive switches, %w double-wrap, require.ErrorIs (lint)
This commit is contained in:
parent
d352a6bce6
commit
2ccc379255
|
|
@ -153,7 +153,7 @@ func (c *Conn) ReadFrame(ctx context.Context) (Frame, error) {
|
||||||
func decodeFrame(msg []byte) (Frame, error) {
|
func decodeFrame(msg []byte) (Frame, error) {
|
||||||
var env rawEnvelope
|
var env rawEnvelope
|
||||||
if err := json.Unmarshal(msg, &env); err != nil {
|
if err := json.Unmarshal(msg, &env); err != nil {
|
||||||
return Frame{}, fmt.Errorf("%w: %v", ErrFrameMalformed, err)
|
return Frame{}, fmt.Errorf("%w: %w", ErrFrameMalformed, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
frame := Frame{
|
frame := Frame{
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ func (c *Collector) handleConn(ctx context.Context, conn *Conn) error {
|
||||||
|
|
||||||
loopErr := ReadLoop(ctx, conn, seq, func(hctx context.Context, f Frame) error {
|
loopErr := ReadLoop(ctx, conn, seq, func(hctx context.Context, f Frame) error {
|
||||||
switch f.Kind {
|
switch f.Kind {
|
||||||
|
case FrameTypeUnknown, FrameTypeSubscriptions, FrameTypeHeartbeats:
|
||||||
|
return nil
|
||||||
case FrameTypeTicker, FrameTypeSnapshot:
|
case FrameTypeTicker, FrameTypeSnapshot:
|
||||||
ts := f.Timestamp.UTC()
|
ts := f.Timestamp.UTC()
|
||||||
if ts.IsZero() {
|
if ts.IsZero() {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ func ReadLoop(ctx context.Context, conn *Conn, seq *Sequencer, handler FrameHand
|
||||||
}
|
}
|
||||||
|
|
||||||
switch frame.Kind {
|
switch frame.Kind {
|
||||||
|
case FrameTypeUnknown, FrameTypeSubscriptions, FrameTypeHeartbeats:
|
||||||
case FrameTypeSnapshot:
|
case FrameTypeSnapshot:
|
||||||
seq.Reset()
|
seq.Reset()
|
||||||
for _, t := range frame.Tickers {
|
for _, t := range frame.Tickers {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ package coinbase_test
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -144,5 +143,5 @@ func TestRepo_LatestTickMissingReturnsErrNoRows(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, err := repo.LatestTick(ctx, "DOES-NOT-EXIST")
|
_, err := repo.LatestTick(ctx, "DOES-NOT-EXIST")
|
||||||
require.True(t, errors.Is(err, sql.ErrNoRows))
|
require.ErrorIs(t, err, sql.ErrNoRows)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue