Files
hmq/plugins/bridge/csvlog_test.go
Gary Barnett 538bf70f5b First Commit (#130)
Co-authored-by: Gary Barnett <gary.barnett@airsensa.com>
2021-11-05 10:28:58 +08:00

37 lines
1.1 KiB
Go

package bridge
import (
"fmt"
"testing"
)
//Test_topicMatch is here to double check the topic matching logic
func Test_topicMatch(t *testing.T) {
tests := []struct {
name string
topic string
filter string
want bool
}{
// Some sample test cases
{name: "Simple", topic: "test", filter: "test", want: true},
{name: "Simple", topic: "test/cat", filter: "test/+", want: true},
{name: "Simple", topic: "test/cat/breed", filter: "test/+", want: false},
{name: "Simple", topic: "test/cat", filter: "test/#", want: true},
{name: "Simple", topic: "test/cat/banana", filter: "test/#", want: true},
{name: "Simple", topic: "test/cat/banana", filter: "test/+", want: false},
{name: "Simple", topic: "test/dog/banana", filter: "test/cat/+", want: false},
{name: "Simple", topic: "test/cat/banana", filter: "test/+/banana", want: true},
}
for _, tt := range tests {
fmt.Println(tt)
t.Run(tt.name, func(t *testing.T) {
if got := topicMatch(tt.topic, tt.filter); got != tt.want {
t.Errorf("topicMatch() = %v, want %v", got, tt.want)
}
})
}
}