in custard/pkg/config/config.go [232:266]
func (c *Config) ValidateCISetup(setup CISetup) []string {
errors := []string{}
validFields := make([]string, 0, len(c.CISetupDefaults))
for k := range c.CISetupDefaults {
validFields = append(validFields, k)
}
slices.Sort(validFields)
fields := make([]string, 0, len(setup))
for k := range setup {
fields = append(fields, k)
}
slices.Sort(fields)
for _, field := range fields {
if strings.HasPrefix(field, "_") {
// This is a comment field, no need to validate.
continue
}
defaultsValue, exists := c.CISetupDefaults[field]
if !exists {
msg := fmt.Sprintf("Unexpected field '%v': valid fields are %v", field, validFields)
errors = append(errors, msg)
} else {
expectedType := reflect.TypeOf(defaultsValue)
gotType := reflect.TypeOf(setup[field])
if gotType != expectedType {
msg := fmt.Sprintf("Unexpected type on '%v': expected '%v', but got '%v'", field, expectedType, gotType)
errors = append(errors, msg)
}
}
}
return errors
}