/
util.go
36 lines (31 loc) · 845 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
33
34
35
36
package framework
import (
"fmt"
"reflect"
"strings"
corev1 "k8s.io/api/core/v1"
)
func CheckEnvVars(want []corev1.EnvVar, have []corev1.EnvVar, includes bool) []error {
var errs []error
for _, val := range want {
found := false
for _, v := range have {
if v.Name == val.Name {
found = true
if includes {
if !strings.Contains(v.Value, val.Value) {
errs = append(errs, fmt.Errorf("environment variable does not contain the expected value: expected %#v, got %#v", val, v))
}
} else {
if !reflect.DeepEqual(v, val) {
errs = append(errs, fmt.Errorf("environment variable does not equal the expected value: expected %#v, got %#v", val, v))
}
}
}
}
if !found {
errs = append(errs, fmt.Errorf("unable to find environment variable: wanted %s", val.Name))
}
}
return errs
}