Permalink
Browse files

Tests for util.go

  • Loading branch information...
jeffjenkins committed Nov 21, 2015
1 parent 686bd9a commit 60bff7ce14ee3340e27e4c2577ee9ec95fb156c4
Showing with 36 additions and 0 deletions.
  1. +36 −0 util/util_test.go
View
@@ -0,0 +1,36 @@
package util
import (
"regexp"
"testing"
"time"
)
func TestRandomId(t *testing.T) {
var re, err = regexp.Compile("^\\w{32}$")
if err != nil {
t.Errorf(err.Error())
}
for i := 0; i < 100; i++ {
var r = RandomId()
if !re.MatchString(r) {
t.Errorf("Did not match string: '%s'", r)
}
}
}
func TestNextId(t *testing.T) {
var now = time.Now().UnixNano()
var next = NextId()
var nextNext = NextId()
if now < next {
t.Errorf("NextId was less than current time")
}
if next+1 != nextNext {
t.Errorf(
"subsequent NextId calls do not produce incrementing numbers: %d, %d",
next,
nextNext,
)
}
}

0 comments on commit 60bff7c

Please sign in to comment.