mirror of
https://github.com/lucacasonato/mqtt.git
synced 2025-09-26 19:01:12 +08:00
Fixed CI
This commit is contained in:
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
@@ -6,6 +6,13 @@ jobs:
|
||||
test:
|
||||
name: ci
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto:latest
|
||||
ports:
|
||||
- 1883
|
||||
env:
|
||||
MQTT_BROKER: tcp://mqtt:1883
|
||||
steps:
|
||||
- name: Set up Go 1.13
|
||||
uses: actions/setup-go@v1
|
||||
@@ -20,6 +27,13 @@ jobs:
|
||||
coverage:
|
||||
name: Coverage
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto:latest
|
||||
ports:
|
||||
- 1883
|
||||
env:
|
||||
MQTT_BROKER: tcp://mqtt:1883
|
||||
steps:
|
||||
- name: Set up Go 1.13
|
||||
uses: actions/setup-go@v1
|
||||
|
3
go.sum
3
go.sum
@@ -2,8 +2,11 @@ github.com/eclipse/paho.mqtt.golang v1.2.0 h1:1F8mhG9+aO5/xpdtFkW4SxOJB67ukuDC3t
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 h1:p9xBe/w/OzkeYVKm234g55gMdD1nSIooTir5kV11kfA=
|
||||
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
38
mqtt_test.go
38
mqtt_test.go
@@ -37,11 +37,11 @@ func TestNewClientNoServer(t *testing.T) {
|
||||
func TestNewClientBasicServer(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -52,11 +52,11 @@ func TestNewClientBasicServer(t *testing.T) {
|
||||
func TestNewClientNoClientID(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err should be nil but is %v", err)
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -70,12 +70,12 @@ func TestNewClientNoClientID(t *testing.T) {
|
||||
func TestNewClientHasClientID(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
ClientID: "client-id",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -89,13 +89,13 @@ func TestNewClientHasClientID(t *testing.T) {
|
||||
func TestNewClientWithAuthentication(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
Username: "user",
|
||||
Password: "password",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -106,18 +106,18 @@ func TestNewClientWithAuthentication(t *testing.T) {
|
||||
func TestConnectSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
}
|
||||
err = client.Connect(ctx())
|
||||
if err != nil {
|
||||
t.Fatal("connect should not have failed")
|
||||
t.Fatalf("connect should not have failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ func TestConnectSuccess(t *testing.T) {
|
||||
func TestConnectContextTimeout(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -146,11 +146,11 @@ func TestConnectContextTimeout(t *testing.T) {
|
||||
func TestConnectContextCancel(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -175,7 +175,7 @@ func TestConnectFailed(t *testing.T) {
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
@@ -190,18 +190,18 @@ func TestConnectFailed(t *testing.T) {
|
||||
func TestDisconnectImmediately(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal("err should be nil")
|
||||
t.Fatalf("creating client failed: %v", err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatal("client should not be nil")
|
||||
}
|
||||
err = client.Connect(ctx())
|
||||
if err != nil {
|
||||
t.Fatal("connect should not have failed")
|
||||
t.Fatalf("connect should not have failed: %v", err)
|
||||
}
|
||||
client.DisconnectImmediately()
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -12,12 +13,19 @@ import (
|
||||
)
|
||||
|
||||
var testUUID = uuid.New().String()
|
||||
var broker = os.Getenv("MQTT_BROKER")
|
||||
|
||||
func init() {
|
||||
if broker == "" {
|
||||
broker = "tcp://localhost:1883"
|
||||
}
|
||||
}
|
||||
|
||||
// TestPublishSuccess checks that a message publish succeeds
|
||||
func TestPublishSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -39,7 +47,7 @@ func TestPublishSuccess(t *testing.T) {
|
||||
func TestPublishContextTimeout(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
defer client.DisconnectImmediately()
|
||||
@@ -62,7 +70,7 @@ func TestPublishContextTimeout(t *testing.T) {
|
||||
func TestPublishContextCancelled(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
defer client.DisconnectImmediately()
|
||||
@@ -89,7 +97,7 @@ func TestPublishContextCancelled(t *testing.T) {
|
||||
func TestPublishFailed(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
defer client.DisconnectImmediately()
|
||||
@@ -110,7 +118,7 @@ func TestPublishFailed(t *testing.T) {
|
||||
func TestPublishSuccessRetained(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -132,7 +140,7 @@ func TestPublishSuccessRetained(t *testing.T) {
|
||||
func TestPublisStringSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -154,7 +162,7 @@ func TestPublisStringSuccess(t *testing.T) {
|
||||
func TestPublisJSONSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -176,7 +184,7 @@ func TestPublisJSONSuccess(t *testing.T) {
|
||||
func TestPublisJSONFailed(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
@@ -17,7 +17,7 @@ func ctx() context.Context {
|
||||
func TestSubcribeSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -77,7 +77,7 @@ func TestSubcribeSuccess(t *testing.T) {
|
||||
func TestSubcribeMultipleSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -137,7 +137,7 @@ func TestSubcribeMultipleSuccess(t *testing.T) {
|
||||
func TestListenSuccess(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -167,7 +167,7 @@ func TestListenSuccess(t *testing.T) {
|
||||
func TestSubcribeFailure(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -188,7 +188,7 @@ func TestSubcribeFailure(t *testing.T) {
|
||||
func TestSubcribeSuccessAdvancedRouting(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -221,7 +221,7 @@ func TestSubcribeSuccessAdvancedRouting(t *testing.T) {
|
||||
func TestSubcribeNoRecieve(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -250,7 +250,7 @@ func TestSubcribeNoRecieve(t *testing.T) {
|
||||
func TestUnsubcribe(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -283,7 +283,7 @@ func TestUnsubcribe(t *testing.T) {
|
||||
func TestRemoveRoute(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -316,7 +316,7 @@ func TestRemoveRoute(t *testing.T) {
|
||||
func TestEmptyRoute(t *testing.T) {
|
||||
client, err := mqtt.NewClient(mqtt.ClientOptions{
|
||||
Servers: []string{
|
||||
"tcp://test.mosquitto.org:1883",
|
||||
broker,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user