forked from openshift/osd-network-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
51 lines (42 loc) · 1.15 KB
/
helpers.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package helpers
import (
_ "embed"
"errors"
"math/rand"
"time"
)
//go:embed config/userdata.yaml
var UserdataTemplate string
// RandSeq generates random string with n characters.
func RandSeq(n int) string {
rand.Seed(time.Now().UnixNano())
b := make([]rune, n)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
// PollImmediate calls the condition function at the specified interval up to the specified timeout
// until the condition function returns true or an error
func PollImmediate(interval time.Duration, timeout time.Duration, condition func() (bool, error)) error {
var totalTime time.Duration = 0
for totalTime < timeout {
cond, err := condition()
if err != nil {
return err
}
if cond {
return nil
}
time.Sleep(interval)
totalTime += interval
}
return errors.New("timed out waiting for the condition")
}
// Enumerated type representing the platform underlying the cluster-under-test
const (
PlatformAWS string = "aws"
PlatformGCP string = "gcp"
PlatformHostedCluster string = "hostedcluster"
)