Added util method IsClientEvent

This commit is contained in:
claudemiro
2016-08-09 23:42:44 -03:00
parent f0b3aadf74
commit 7a794c97d7
4 changed files with 27 additions and 3 deletions
+7
View File
@@ -40,10 +40,17 @@ func IsChannelNameValid(channelName string) bool {
return validChannelName.Match([]byte(channelName))
}
// IsPrivateChannel Verify if the channel name represents a private channel
func IsPrivateChannel(channelName string) bool {
return strings.HasPrefix(channelName, "private-")
}
// IsPresenceChannel Verify if the channel name represents a presence channel
func IsPresenceChannel(channelName string) bool {
return strings.HasPrefix(channelName, "presence-")
}
// IsClientEvent Verify if the event name represents a client event type
func IsClientEvent(event string) bool {
return strings.HasPrefix(event, "client-")
}
+18
View File
@@ -95,6 +95,24 @@ func TestIsPresenceChannel_invalid(t *testing.T) {
}
}
func TestIsClientEvent_valid(t *testing.T) {
name := "client-hello"
ok := IsClientEvent(name)
if !ok {
t.Errorf("IsClientEvent(%s) == %t, wants %t", name, ok, true)
}
}
func TestIsClientEvent_invalid(t *testing.T) {
name := "hello"
ok := IsClientEvent(name)
if ok {
t.Errorf("IsClientEvent(%s) == %t, wants %t", name, ok, false)
}
}
func TestHashMAC(t *testing.T) {
message := []byte("hello world")
key := []byte("my super secret key")