-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutilities.go
51 lines (46 loc) · 1.07 KB
/
utilities.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 test
import (
"os"
"reflect"
"strings"
"testing"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
)
func UnSetDriverEnvironmentVars(t *testing.T) {
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
if strings.HasPrefix(pair[0], "CNAB_AZURE") {
t.Logf("Unsetting Env Variable: %s", pair[0])
os.Unsetenv(pair[0])
}
}
}
func GetFieldValue(t *testing.T, i interface{}, field string) interface{} {
r := reflect.ValueOf(i)
f := reflect.Indirect(r).FieldByName(field)
if f.IsValid() {
switch f.Kind() {
case reflect.String:
return f.String()
case reflect.Int:
return f.Int()
case reflect.Bool:
return f.Bool()
default:
t.Errorf("field %s has unexpected type %s ", field, f.Kind())
return nil
}
}
t.Errorf("Unable to get value for field %s ", field)
return nil
}
func SetLoggingLevel(verbose *bool) {
if *verbose {
log.SetLevel(log.DebugLevel)
}
}
func SetStatePathEnvironmentVariables() {
os.Setenv("CNAB_AZURE_STATE_MOUNT_POINT", "/cnab/app/state/")
os.Setenv("CNAB_AZURE_STATE_PATH", uuid.New().String())
}