From 6f31b3d4034b2fc76ff8d3a8195c76e4ff56ccbc Mon Sep 17 00:00:00 2001 From: Arne Van Maele Date: Tue, 19 Dec 2023 09:04:14 +0100 Subject: [PATCH] fix (#661): Add NewClientOptionsReader for mocking purposes. --- options_reader.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/options_reader.go b/options_reader.go index 10a9e49..395075f 100644 --- a/options_reader.go +++ b/options_reader.go @@ -30,6 +30,21 @@ type ClientOptionsReader struct { options *ClientOptions } +// NewOptionsReader creates a ClientOptionsReader, this should only be used for mocking purposes. +// +// An example implementation: +// +// func (c *mqttClientMock) OptionsReader() mqtt.ClientOptionsReader { +// opts := mqtt.NewClientOptions() +// opts.UserName = "TestUserName" +// return mqtt.NewOptionsReader(opts) +// } +func NewOptionsReader(o *ClientOptions) ClientOptionsReader { + return ClientOptionsReader{ + options: o, + } +} + // Servers returns a slice of the servers defined in the clientoptions func (r *ClientOptionsReader) Servers() []*url.URL { s := make([]*url.URL, len(r.options.Servers))