Skip to content

Commit

Permalink
feat: add a few sane websocket defaults
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schmidtw committed May 15, 2024
1 parent f232afc commit 07a96a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/websocket/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions internal/websocket/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,7 @@ func TestLimit(t *testing.T) {
})
}
}

func Test_emptyDecorator(t *testing.T) {
assert.NoError(t, emptyDecorator(http.Header{}))
}

0 comments on commit 07a96a5

Please sign in to comment.