This commit is contained in:
asteam
2026-01-16 16:50:40 +03:00
parent bb90a2d511
commit 365a4991d2
24 changed files with 191 additions and 39 deletions

View File

@@ -693,6 +693,7 @@ func getRequestsMapCloudbroker() map[string]interface{} {
"/restmachine/cloudbroker/disks/migrate": disks_cb.MigrateRequest{},
"/restmachine/cloudbroker/disks/migrate_abort": disks_cb.MigrateAbortRequest{},
"/restmachine/cloudbroker/disks/migrate_status": disks_cb.GetMigrateStatusRequest{},
"/restmachine/cloudbroker/disks/update": disks_cb.UpdateRequest{},
// dpdknet
"/restmachine/cloudbroker/dpdknet/get": dpdknet_cb.GetRequest{},
@@ -889,7 +890,7 @@ func getRequestsMapCloudbroker() map[string]interface{} {
"/restmachine/cloudbroker/node/setVFsNumber": node_cb.SetVFsNumberRequest{},
"/restmachine/cloudbroker/node/update": node_cb.UpdateRequest{},
"/restmachine/cloudbroker/node/update_description": node_cb.UpdateDescriptionRequest{},
"/restmachine/cloudbroker/node/setVFsParams": node_cb.VFParam{},
"/restmachine/cloudbroker/node/setVFsParams": node_cb.SetVFsParamsRequest{},
"/restmachine/cloudbroker/node/get_logical_cores_count": node_cb.GetLogicalCoresCountRequest{},
"/restmachine/cloudbroker/node/set_cpu_allocation_ratio": node_cb.SetCpuAllocationRatioRequest{},
"/restmachine/cloudbroker/node/set_mem_allocation_ratio": node_cb.SetMemAllocationRatioRequest{},

View File

@@ -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)