Files
ipe/utils/utils_test.go
T
claudemiro 517462a7af Cache of the valid channel name regex
* Added a Benchmark to verify the performance
* Now it is 10 times faster
2016-01-23 22:25:14 -02:00

49 lines
1.0 KiB
Go

// Copyright 2015 Claudemiro Alves Feitosa Neto. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package utils
import (
"regexp"
"testing"
)
func BenchmarkGenerateSession(b *testing.B) {
for i := 0; i < b.N; i++ {
GenerateSessionID()
}
}
func BenchmarkIsChannelNameValid(b *testing.B) {
for i := 0; i < b.N; i++ {
IsChannelNameValid("hello-world")
}
}
func TestGenerateSession(t *testing.T) {
sessionID := GenerateSessionID()
if matched, _ := regexp.MatchString("^\\d+\\.\\d+$", sessionID); !matched {
t.Errorf("Must match ^\\d+\\.\\d+$, value: '%s'", sessionID)
}
}
func TestIsValidChannelName(t *testing.T) {
if IsChannelNameValid("#@#hhh**sasas") {
t.Errorf("Invalid Channel Name")
}
if !IsChannelNameValid("private-hello") {
t.Errorf("Must be Valid Channel Name")
}
if !IsChannelNameValid("presence-hello") {
t.Errorf("Must be Valid Channel Name")
}
if !IsChannelNameValid("public") {
t.Errorf("Must be Valid Channel Name")
}
}