Skip to content

Commit

Permalink
Added a compliance test and a GH action to run it
Browse files Browse the repository at this point in the history
  • Loading branch information
levb committed Oct 3, 2023
1 parent e5d3f4a commit 5bbf804
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/MQTT test.yaml
@@ -0,0 +1,37 @@
name: MQTT Compliance
on: [push, pull_request]

jobs:
test:
strategy:
matrix:
go: ["1.21"]
env:
GOPATH: /home/runner/work/nats-server
GO111MODULE: "on"

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
path: src/github.com/nats-io/nats-server

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{matrix.go}}

- name: Install deps
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
wget https://github.com/hivemq/mqtt-cli/releases/download/v4.20.0/mqtt-cli-4.20.0.deb
sudo apt install ./mqtt-cli-4.20.0.deb
- name: Run tests
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
set -e
cd src/github.com/nats-io/nats-server/server
go test -v -vet=off --run=TestMQTTCLICompliance
set +e
36 changes: 36 additions & 0 deletions server/mqtt_test.go
Expand Up @@ -27,7 +27,9 @@ import (
"math/rand"
"net"
"os"
"os/exec"
"reflect"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -6997,6 +6999,40 @@ func TestMQTTJetStreamRepublishAndQoS0Subscribers(t *testing.T) {
testMQTTExpectNothing(t, r)
}

func TestMQTTCLICompliance(t *testing.T) {
mqttPath := os.Getenv("MQTT_CLI")
if mqttPath == "" {
if p, err := exec.LookPath("mqtt"); err == nil {
mqttPath = p
}
}
if mqttPath == "" {
t.Skip(`"mqtt" command is not found in $PATH nor $MQTT_CLI. See https://hivemq.github.io/mqtt-cli/docs/installation/#debian-package for installation instructions`)
}

conf := createConfFile(t, []byte(fmt.Sprintf(`
listen: 127.0.0.1:-1
server_name: mqtt
jetstream {
store_dir = %q
}
mqtt {
listen: 127.0.0.1:-1
}
`, t.TempDir())))
s, o := RunServerWithConfig(conf)
defer testMQTTShutdownServer(s)

cmd := exec.Command(mqttPath, "test", "-V", "3", "-p", strconv.Itoa(o.MQTT.Port))

if output, err := cmd.CombinedOutput(); err != nil {
t.Log(string(output))
if exitError, ok := err.(*exec.ExitError); ok {
t.Fatalf("mqtt cli exited with error: %v", exitError)
}
}
}

//////////////////////////////////////////////////////////////////////////
//
// Benchmarks
Expand Down

0 comments on commit 5bbf804

Please sign in to comment.