-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
744 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
broker_addr=localhost:30083 | ||
|
||
all: | ||
go test ./... -addr $(broker_addr) -json|go-test-report | ||
|
||
clean: | ||
rm -fr test_report.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module bigwhite/autotester | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed h1:ue9pVfIcP+QMEjfgo/Ez4ZjNZfonGgR6NgjMaJMu1Cg= | ||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY= | ||
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4= | ||
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA= | ||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= | ||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U= | ||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= | ||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package connection | ||
|
||
import ( | ||
"testing" | ||
|
||
mqtt "github.com/eclipse/paho.mqtt.golang" | ||
) | ||
|
||
func Test_Connection_S0001_ConnectOKWithoutAuth(t *testing.T) { | ||
opts := mqtt.NewClientOptions() | ||
opts.AddBroker("tcp://" + addr) | ||
|
||
// Create and start MQTT client | ||
client := mqtt.NewClient(opts) | ||
token := client.Connect() | ||
token.Wait() | ||
|
||
// Check if connection was successful | ||
if token.Error() != nil { | ||
t.Errorf("want ok, got %v", token.Error()) | ||
return | ||
} | ||
client.Disconnect(0) | ||
} | ||
|
||
func Test_Connection_S0002_ConnectOKWithAuth(t *testing.T) { | ||
//... ... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package connection | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
mqtt "github.com/eclipse/paho.mqtt.golang" | ||
) | ||
|
||
var addr string | ||
|
||
func init() { | ||
flag.StringVar(&addr, "addr", "", "the broker address(ip:port)") | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
|
||
// setup for this scenario | ||
mqtt.ERROR = log.New(os.Stdout, "[ERROR] ", 0) | ||
/* | ||
mqtt.CRITICAL = log.New(os.Stdout, "[CRIT] ", 0) | ||
mqtt.WARN = log.New(os.Stdout, "[WARN] ", 0) | ||
mqtt.DEBUG = log.New(os.Stdout, "[DEBUG] ", 0) | ||
*/ | ||
|
||
// run this scenario test | ||
r := m.Run() | ||
|
||
// teardown for this scenario | ||
// tbd if teardown is needed | ||
|
||
os.Exit(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package publish | ||
|
||
import ( | ||
scenarios "bigwhite/autotester/scenarios" | ||
"testing" | ||
) | ||
|
||
func Test_Publish_S0001_PublishOK(t *testing.T) { | ||
client, testCaseTeardown, err := scenarios.TestCaseSetup(addr, nil) | ||
if err != nil { | ||
t.Errorf("want ok, got %v", err) | ||
return | ||
} | ||
defer testCaseTeardown() | ||
|
||
//TBD:xxx | ||
_ = client | ||
_ = err | ||
} | ||
|
||
func Test_Publish_S0002_PublishFail(t *testing.T) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package publish | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
mqtt "github.com/eclipse/paho.mqtt.golang" | ||
) | ||
|
||
var addr string | ||
|
||
func init() { | ||
flag.StringVar(&addr, "addr", "", "the broker address(ip:port)") | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
|
||
// setup for this scenario | ||
mqtt.ERROR = log.New(os.Stdout, "[ERROR] ", 0) | ||
/* | ||
mqtt.CRITICAL = log.New(os.Stdout, "[CRIT] ", 0) | ||
mqtt.WARN = log.New(os.Stdout, "[WARN] ", 0) | ||
mqtt.DEBUG = log.New(os.Stdout, "[DEBUG] ", 0) | ||
*/ | ||
|
||
// run this scenario test | ||
r := m.Run() | ||
|
||
// teardown for this scenario | ||
// tbd if teardown is needed | ||
|
||
os.Exit(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package scenarios | ||
|
||
import ( | ||
mqtt "github.com/eclipse/paho.mqtt.golang" | ||
) | ||
|
||
func TestCaseSetup(addr string, opts *mqtt.ClientOptions) (client mqtt.Client, testCaseTeardown func(), err error) { | ||
if opts == nil { | ||
opts = mqtt.NewClientOptions() | ||
} | ||
opts.AddBroker("tcp://" + addr) | ||
|
||
// Create and start MQTT client | ||
client = mqtt.NewClient(opts) | ||
token := client.Connect() | ||
token.Wait() | ||
|
||
err = token.Error() | ||
testCaseTeardown = func() { | ||
client.Disconnect(0) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package subscribe | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
mqtt "github.com/eclipse/paho.mqtt.golang" | ||
) | ||
|
||
var addr string | ||
|
||
func init() { | ||
flag.StringVar(&addr, "addr", "", "the broker address(ip:port)") | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
|
||
// setup for this scenario | ||
mqtt.ERROR = log.New(os.Stdout, "[ERROR] ", 0) | ||
/* | ||
mqtt.CRITICAL = log.New(os.Stdout, "[CRIT] ", 0) | ||
mqtt.WARN = log.New(os.Stdout, "[WARN] ", 0) | ||
mqtt.DEBUG = log.New(os.Stdout, "[DEBUG] ", 0) | ||
*/ | ||
|
||
// run this scenario test | ||
r := m.Run() | ||
|
||
// teardown for this scenario | ||
// tbd if teardown is needed | ||
|
||
os.Exit(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package subscribe | ||
|
||
import ( | ||
scenarios "bigwhite/autotester/scenarios" | ||
"testing" | ||
) | ||
|
||
func Test_Subscribe_S0001_SubscribeOK(t *testing.T) { | ||
t.Parallel() // indicate the case can be ran in parallel mode | ||
|
||
tests := []struct { | ||
name string | ||
topic string | ||
qos byte | ||
}{ | ||
{ | ||
name: "Case_001: Subscribe with QoS 0", | ||
topic: "a/b/c", | ||
qos: 0, | ||
}, | ||
{ | ||
name: "Case_002: Subscribe with QoS 1", | ||
topic: "a/b/c", | ||
qos: 1, | ||
}, | ||
{ | ||
name: "Case_003: Subscribe with QoS 2", | ||
topic: "a/b/c", | ||
qos: 2, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() // indicate the case can be ran in parallel mode | ||
client, testCaseTeardown, err := scenarios.TestCaseSetup(addr, nil) | ||
if err != nil { | ||
t.Errorf("want ok, got %v", err) | ||
return | ||
} | ||
defer testCaseTeardown() | ||
|
||
token := client.Subscribe(tt.topic, tt.qos, nil) | ||
token.Wait() | ||
|
||
// Check if subscription was successful | ||
if token.Error() != nil { | ||
t.Errorf("want ok, got %v", token.Error()) | ||
} | ||
|
||
token = client.Unsubscribe(tt.topic) | ||
token.Wait() | ||
if token.Error() != nil { | ||
t.Errorf("want ok, got %v", token.Error()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_Subscribe_S0002_SubscribeFail(t *testing.T) { | ||
} |
Oops, something went wrong.