Graphtest is ok to compile normally
The graphtest package is only imported in the test files of other packages therefore we do not leak testing flags. Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
parent
1543060953
commit
cfa9032def
1 changed files with 0 additions and 0 deletions
37
testutils/utils.go
Normal file
37
testutils/utils.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package testutils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const chars = "abcdefghijklmnopqrstuvwxyz" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
"~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
|
||||
|
||||
// Timeout calls f and waits for 100ms for it to complete.
|
||||
// If it doesn't, it causes the tests to fail.
|
||||
// t must be a valid testing context.
|
||||
func Timeout(t *testing.T, f func()) {
|
||||
onTimeout := time.After(100 * time.Millisecond)
|
||||
onDone := make(chan bool)
|
||||
go func() {
|
||||
f()
|
||||
close(onDone)
|
||||
}()
|
||||
select {
|
||||
case <-onTimeout:
|
||||
t.Fatalf("timeout")
|
||||
case <-onDone:
|
||||
}
|
||||
}
|
||||
|
||||
// RandomString returns random string of specified length
|
||||
func RandomString(length int) string {
|
||||
res := make([]byte, length)
|
||||
for i := 0; i < length; i++ {
|
||||
res[i] = chars[rand.Intn(len(chars))]
|
||||
}
|
||||
return string(res)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue