Skip to content

Commit c545dea

Browse files
committed
QA
1 parent 79d41f7 commit c545dea

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
mqttinfo is a command-line utility to retrieve information on an MQTT broker.
44

5+
To get the mqttinfo utility, you may run:
6+
7+
```
8+
go get -u -v github.com/Teserakt-io/mqttinfo/cmd/mqttinfo
9+
```
10+
11+
Otherwise, clone this repository and run `./scripts/build.sh` to build
12+
mqttinfo, then run it from `./bin/mqttinfo`.
13+
514
Usage:
615

716
```

cmd/mqttinfo/main.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,24 @@ func main() {
5555
}
5656

5757
if len(gitTag) == 0 {
58-
fmt.Printf("MQTTinfo – version %v-%v\n", buildDate, gitCommit[:4])
58+
fmt.Printf("MQTTinfo – version %v-%v\n", buildDate, gitCommit)
5959
} else {
60-
fmt.Printf("MQTTinfo – version %s (%v-%v)\n", gitTag, buildDate, gitCommit[:4])
60+
fmt.Printf("MQTTinfo – version %s (%v-%v)\n", gitTag, buildDate, gitCommit)
6161
}
6262

6363
fmt.Println("Copyright (c) Teserakt AG, 2019")
6464

6565
// info will hold the results of the analysis
66-
b := mqttinfo.NewBrokerInfo(*hostname, *port, *username, *password)
66+
b, err := mqttinfo.NewBrokerInfo(*hostname, *port, *username, *password)
67+
if err != nil {
68+
fmt.Printf("BrokerInfo creation failed: %v\n", err)
69+
b.Failed = true
70+
b.Error = err.Error()
71+
return
72+
}
6773

6874
fmt.Printf("\nTarget: %v:%v\n", b.Host, b.Port)
6975

70-
var err error
71-
7276
// v3.1.1 tests
7377
fmt.Printf("\nChecking %v broker interface...\n", v4)
7478
err = b.CheckConnectionV4()

pkg/mqttinfolib/mqttinfolib.go

+8-22
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const (
9393
)
9494

9595
// NewBrokerInfo creates a BrokerInfo with default values
96-
func NewBrokerInfo(hostname string, port int, username, password string) BrokerInfo {
96+
func NewBrokerInfo(hostname string, port int, username, password string) (*BrokerInfo, error) {
9797
b := BrokerInfo{}
9898
b.Host = hostname
9999
b.Port = port
@@ -103,32 +103,15 @@ func NewBrokerInfo(hostname string, port int, username, password string) BrokerI
103103
b.V4 = false
104104
b.V5 = false
105105

106-
b.V4Anonymous = false
107-
b.V4PublishSYS = false
108106
b.V4FilterSYS = true
109-
b.V4SubscribeAll = false
110-
b.V4InvalidTopics = false
111-
b.V4InvalidUTF8Topic = false
112-
b.V4QoS1 = false
113-
b.V4QoS2 = false
114-
b.V4QoS3Response = false
115-
116-
b.V5Anonymous = false
117-
b.V5PublishSYS = false
118107
b.V5FilterSYS = true
119-
b.V5SubscribeAll = false
120-
b.V5InvalidTopics = false
121-
b.V5InvalidUTF8Topic = false
122-
b.V5QoS1 = false
123-
b.V5QoS2 = false
124-
b.V5QoS3Response = false
125-
126108
b.TypeGuessed = "unknown"
127109

128-
b.Failed = false
129110
b.Error = ""
130111

131-
return b
112+
// Boolean values default to false
113+
114+
return &b, nil
132115
}
133116

134117
// varint encoding, this function copied from https://github.com/eclipse/paho.mqtt.golang
@@ -259,7 +242,10 @@ func (b *BrokerInfo) connectV5() (net.Conn, error) {
259242
return nil, err
260243
}
261244

262-
conn.Write(b.getConnectV5())
245+
_, err = conn.Write(b.getConnectV5())
246+
if err != nil {
247+
return nil, fmt.Errorf("CONNACK read failed: %v", err)
248+
}
263249
connack := make([]byte, 100)
264250
_, err = conn.Read(connack)
265251
if err != nil {

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ echo ""
77

88
goimports -w cmd/$PROJECT
99

10-
GIT_COMMIT=$(git rev-list -1 HEAD)
10+
GIT_COMMIT=$(git rev-parse --short HEAD)
1111
GIT_TAG=$(git describe --exact-match HEAD)
1212
NOW=$(date "+%Y%m%d")
1313

0 commit comments

Comments
 (0)