Skip to content

Commit 6f31b3d

Browse files
committed
fix (#661): Add NewClientOptionsReader for mocking purposes.
1 parent 5786441 commit 6f31b3d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

options_reader.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ type ClientOptionsReader struct {
3030
options *ClientOptions
3131
}
3232

33+
// NewOptionsReader creates a ClientOptionsReader, this should only be used for mocking purposes.
34+
//
35+
// An example implementation:
36+
//
37+
// func (c *mqttClientMock) OptionsReader() mqtt.ClientOptionsReader {
38+
// opts := mqtt.NewClientOptions()
39+
// opts.UserName = "TestUserName"
40+
// return mqtt.NewOptionsReader(opts)
41+
// }
42+
func NewOptionsReader(o *ClientOptions) ClientOptionsReader {
43+
return ClientOptionsReader{
44+
options: o,
45+
}
46+
}
47+
3348
// Servers returns a slice of the servers defined in the clientoptions
3449
func (r *ClientOptionsReader) Servers() []*url.URL {
3550
s := make([]*url.URL, len(r.options.Servers))

0 commit comments

Comments
 (0)