From 07a96a50a6dfea45fe24cac665bf44c328e27fa3 Mon Sep 17 00:00:00 2001 From: schmidtw Date: Tue, 14 May 2024 20:03:00 -0700 Subject: [PATCH] feat: add a few sane websocket defaults For testing and other cases it's nice to automatically have an empty *http.Client as well as empty decorators when they aren't definitely needed. --- internal/websocket/ws.go | 10 +++++++++- internal/websocket/ws_test.go | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/websocket/ws.go b/internal/websocket/ws.go index f91fe6c..7cc47bf 100644 --- a/internal/websocket/ws.go +++ b/internal/websocket/ws.go @@ -113,9 +113,17 @@ func (f optionFunc) apply(c *Websocket) error { return f(c) } +func emptyDecorator(http.Header) error { + return nil +} + // New creates a new WS connection with the given options. func New(opts ...Option) (*Websocket, error) { - var ws Websocket + ws := Websocket{ + credDecorator: emptyDecorator, + conveyDecorator: emptyDecorator, + client: &http.Client{}, + } opts = append(opts, validateDeviceID(), diff --git a/internal/websocket/ws_test.go b/internal/websocket/ws_test.go index 88d027d..a41ca28 100644 --- a/internal/websocket/ws_test.go +++ b/internal/websocket/ws_test.go @@ -428,3 +428,7 @@ func TestLimit(t *testing.T) { }) } } + +func Test_emptyDecorator(t *testing.T) { + assert.NoError(t, emptyDecorator(http.Header{})) +}