fayec/subscription/subscription_test.go

84 lines
1.4 KiB
Go
Raw Normal View History

package subscription
import (
"testing"
)
/*
assertEqual( ["/**", "/foo", "/*"],
channel.expand("/foo") )
assertEqual( ["/**", "/foo/bar", "/foo/*", "/foo/**"],
channel.expand("/foo/bar") )
assertEqual( ["/**", "/foo/bar/qux", "/foo/bar/*", "/foo/**", "/foo/bar/**"],
*/
func TestIsValidSubscriptionName(t *testing.T) {
type args struct {
channel string
}
tests := []struct {
name string
args args
want bool
}{
{
2018-09-12 07:45:47 +00:00
name: "single asterisk",
args: args{
channel: "/*",
},
want: true,
},
{
2018-09-12 07:45:47 +00:00
name: "double asterisk",
args: args{
channel: "/**",
},
want: true,
},
{
name: "regular channel",
args: args{
channel: "/foo",
},
want: true,
},
{
name: "regular channel 2",
args: args{
channel: "/foo/bar",
},
want: true,
},
{
name: "invalid slash ending",
args: args{
channel: "/foo/",
},
want: false,
},
{
2018-09-12 07:45:47 +00:00
name: "invalid asterisk at the middle",
args: args{
channel: "/foo/**/bar",
},
want: false,
},
{
name: "asterisk before slash",
args: args{
channel: "/foo*",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsValidSubscriptionName(tt.args.channel); got != tt.want {
t.Errorf("isValidChannelName() = %v, want %v", got, tt.want)
}
})
}
}