forked from kubevirt/hyperconverged-cluster-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
74 lines (58 loc) · 1.35 KB
/
config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tests
import (
"flag"
"io/ioutil"
"sync"
"gopkg.in/yaml.v2"
)
const (
ConfigFileFlag = "config-file"
)
var (
configFileName string
config *TestConfig
)
type QuickStartTestItem struct {
Name string `yaml:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty"`
}
type QuickStartTestConfig struct {
TestItems []QuickStartTestItem `yaml:"testItems,omitempty"`
}
type DashboardTestItem struct {
Name string `yaml:"name,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
// keys expected in the configmap
Keys []string `yaml:"keys,omitempty"`
}
type DashboardTestConfig struct {
TestItems []DashboardTestItem `yaml:"testItems,omitempty"`
}
type TestConfig struct {
QuickStart QuickStartTestConfig `yaml:"quickStart,omitempty"`
Dashboard DashboardTestConfig `yaml:"dashboard,omitempty"`
}
func init() {
flag.StringVar(&configFileName, ConfigFileFlag, "", "File contains test configuration")
}
func GetConfig() *TestConfig {
once := sync.Once{}
once.Do(func() {
config = loadConfig(configFileName)
})
return config
}
func loadConfig(fileName string) *TestConfig {
config := TestConfig{}
if fileName != "" {
configContent, err := ioutil.ReadFile(fileName)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(configContent, &config)
if err != nil {
panic(err)
}
}
return &config
}