v1.13.4
This commit is contained in:
@@ -238,6 +238,25 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
|
||||
if len(params) != typStruct.NumField() {
|
||||
errs = append(errs, fmt.Sprintf("Platform (%d) and golang structure (%d) have different amount of fields.", len(params), typStruct.NumField()))
|
||||
}
|
||||
paramMap := make(map[string]bool)
|
||||
paramRequiredMap := make(map[string]bool)
|
||||
for _, p := range params {
|
||||
param, ok := p.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name, ok := param["name"].(string)
|
||||
if ok {
|
||||
paramMap[name] = true
|
||||
required, ok := param["required"].(bool)
|
||||
if ok {
|
||||
paramRequiredMap[name] = required
|
||||
} else {
|
||||
paramRequiredMap[name] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range params {
|
||||
param, ok := p.(map[string]interface{})
|
||||
if !ok {
|
||||
@@ -292,6 +311,33 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
|
||||
errs = append(errs, fmt.Sprintf("Platform has field %s that golang structure doesn't", name))
|
||||
}
|
||||
}
|
||||
|
||||
// Check if required fields in Go structure are missing from platform JSON
|
||||
// or if they exist but are not required on platform
|
||||
for i := 0; i < typStruct.NumField(); i++ {
|
||||
jsonTag := typStruct.Field(i).Tag.Get("json")
|
||||
validation, _ := typStruct.Field(i).Tag.Lookup("validate")
|
||||
|
||||
fieldName := strings.Split(jsonTag, ",")[0]
|
||||
if fieldName == "" || fieldName == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(validation, "required") {
|
||||
if !paramMap[fieldName] {
|
||||
errs = append(errs, fmt.Sprintf("Golang structure has required field %s that platform doesn't", fieldName))
|
||||
} else {
|
||||
platformRequired := paramRequiredMap[fieldName]
|
||||
if !platformRequired {
|
||||
fieldType := typStruct.Field(i).Type
|
||||
if fieldType.Kind() == reflect.Bool {
|
||||
errs = append(errs, fmt.Sprintf("Golang structure has required field %s that platform doesn't", fieldName))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
msg := fmt.Sprintf("Path %s has following errors: %v", k, errs)
|
||||
t.Error(msg)
|
||||
|
||||
Reference in New Issue
Block a user