|
| 1 | +package longhorn |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "slices" |
| 6 | + |
| 7 | + "github.com/rancher/shepherd/pkg/config" |
| 8 | + "github.com/rancher/tests/actions/storage" |
| 9 | +) |
| 10 | + |
| 11 | +// The json/yaml config key for the corral package to be build .. |
| 12 | +const ( |
| 13 | + longhornTestConfigConfigurationFileKey = "longhorn" |
| 14 | + LonghornTestDefaultProject = "longhorn-test" |
| 15 | + LonghornTestDefaultStorageClass = "longhorn" |
| 16 | +) |
| 17 | + |
| 18 | +type TestConfig struct { |
| 19 | + LonghornTestProject string `json:"testProject,omitempty"` |
| 20 | + LonghornTestStorageClass string `json:"testStorageClass,omitempty"` |
| 21 | +} |
| 22 | + |
| 23 | +// GetLonghornTestConfig gets a LonghornTestConfig object using the data from the config file. |
| 24 | +func GetLonghornTestConfig() *TestConfig { |
| 25 | + var longhornTestConfig TestConfig |
| 26 | + config.LoadConfig(longhornTestConfigConfigurationFileKey, &longhornTestConfig) |
| 27 | + |
| 28 | + defer func() { |
| 29 | + if r := recover(); r != nil { |
| 30 | + longhornTestConfig = TestConfig{ |
| 31 | + LonghornTestProject: LonghornTestDefaultProject, |
| 32 | + LonghornTestStorageClass: LonghornTestDefaultStorageClass, |
| 33 | + } |
| 34 | + } else { |
| 35 | + if !slices.Contains(storage.LonghornStorageClasses, longhornTestConfig.LonghornTestStorageClass) { |
| 36 | + panic(fmt.Errorf("Invalid storage class %s", longhornTestConfig.LonghornTestStorageClass)) |
| 37 | + } |
| 38 | + } |
| 39 | + }() |
| 40 | + |
| 41 | + if longhornTestConfig.LonghornTestProject == "" { |
| 42 | + longhornTestConfig.LonghornTestProject = LonghornTestDefaultProject |
| 43 | + } |
| 44 | + |
| 45 | + if longhornTestConfig.LonghornTestStorageClass == "" { |
| 46 | + longhornTestConfig.LonghornTestStorageClass = LonghornTestDefaultStorageClass |
| 47 | + } |
| 48 | + |
| 49 | + return &longhornTestConfig |
| 50 | +} |
0 commit comments