/
util.go
32 lines (27 loc) · 862 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package testutil
import (
"math/rand"
"testing"
)
// RunAndCheckCoverage use this in order to let the test fail when a coverage is not reached
func RunAndCheckCoverage(testPackage string, m *testing.M, treshold float64) int {
// rand.Seed(time.Now().UnixNano())
code := m.Run()
// if code == 0 && testing.CoverMode() != "" {
// coverage := testing.Coverage()
// if coverage < treshold {
// log.Printf("%s tests passed, but coverage must be above %2.2f%%, but it is %2.2f%%\n", testPackage, treshold*100, coverage*100)
// code = -1
// }
// }
return code
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// RandString create a random string with n letters
func RandString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
}
return string(b)
}