Skip to content

Commit

Permalink
fix subhost issue
Browse files Browse the repository at this point in the history
Signed-off-by: RockyJin <[email protected]>

fix testcase issue

fix testcase issue

fix testcase issue

fix testcase issue

go format code
  • Loading branch information
jinfahua committed Apr 14, 2020
1 parent cfba307 commit 094e2ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion internal/pkg/mqtt/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ type MQTTClientOptions struct {

// CreateMQTTClientConfiguration constructs a MQTTClientConfig based on the provided MessageBusConfig.
func CreateMQTTClientConfiguration(messageBusConfig types.MessageBusConfig) (MQTTClientConfig, error) {
brokerUrl := messageBusConfig.PublishHost.GetHostURL()
var brokerUrl string
if !messageBusConfig.PublishHost.IsHostInfoEmpty() {
brokerUrl = messageBusConfig.PublishHost.GetHostURL()
} else if !messageBusConfig.SubscribeHost.IsHostInfoEmpty() {
brokerUrl = messageBusConfig.SubscribeHost.GetHostURL()
} else {
return MQTTClientConfig{}, fmt.Errorf("Specified empty broker info.")
}

_, err := url.Parse(brokerUrl)
if err != nil {
return MQTTClientConfig{}, pkg.NewBrokerURLErr(fmt.Sprintf("Failed to parse broker: %v", err))
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/mqtt/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ var OptionalPropertiesCertLoad = map[string]string{
mqtt.KeyFile: "./key",
}

var TcpHostInfo = types.HostInfo{Host: "localhost", Protocol: "tcp"}
var TlsHostInfo = types.HostInfo{Host: "localhost", Protocol: "tls"}
var TcpsHostInfo = types.HostInfo{Host: "localhost", Protocol: "tcps"}
var SslHostInfo = types.HostInfo{Host: "localhost", Protocol: "ssl"}
var TcpHostInfo = types.HostInfo{Host: "localhost", Protocol: "tcp", Port: 1883}
var TlsHostInfo = types.HostInfo{Host: "localhost", Protocol: "tls", Port: 8883}
var TcpsHostInfo = types.HostInfo{Host: "localhost", Protocol: "tcps", Port: 8883}
var SslHostInfo = types.HostInfo{Host: "localhost", Protocol: "ssl", Port: 8883}

// TestMessageBusConfig defines a simple configuration used for testing successful options parsing.
var TestMessageBusConfig = types.MessageBusConfig{
Expand Down

0 comments on commit 094e2ca

Please sign in to comment.