Added disconnect function

This commit is contained in:
Luca Casonato
2019-10-20 00:13:39 +02:00
parent 6ffd2c59e7
commit 37ce340357
3 changed files with 42 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ on: [push]
jobs:
test:
name: Test & Coverage
name: Tests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
@@ -16,7 +16,21 @@ jobs:
- name: Get dependencies
run: go mod download
- name: Run tests & coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic
run: go test -race
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Check out code
uses: actions/checkout@v1
- name: Get dependencies
run: go mod download
- name: Run tests & coverage
run: go test -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1.0.3
with:

View File

@@ -81,3 +81,8 @@ func (c *Client) Connect(ctx context.Context) error {
}
}
}
// Disconnect will immediately close the conenction with the mqtt servers
func (c *Client) DisconnectImmediately() {
c.client.Disconnect(0)
}

View File

@@ -189,3 +189,24 @@ func TestConnectFailed(t *testing.T) {
t.Fatal("connect should have failed")
}
}
// check that a client gets created and a client id is not changed when it is set
func TestDisconnectImmediately(t *testing.T) {
client, err := mqtt.NewClient(mqtt.ClientOptions{
Servers: []string{
"tcp://test.mosquitto.org:1883",
},
AutoReconnect: false,
})
if err != nil {
t.Fatal("err should be nil")
}
if client == nil {
t.Fatal("client should not be nil")
}
err = client.Connect(context.Background())
if err != nil {
t.Fatal("connect should not have failed")
}
client.DisconnectImmediately()
}