This commit is contained in:
asteam
2025-08-29 12:51:25 +03:00
parent e10ee7f801
commit 825b1a0a00
177 changed files with 4821 additions and 349 deletions

View File

@@ -11,12 +11,24 @@ import (
func getParameters(input map[string]interface{}) []interface{} {
var emptySlice []interface{}
post, ok := input["post"]
if !ok {
methods := []string{"get", "post", "put", "delete", "patch", "head", "options"}
var methodData interface{}
found := false
for _, method := range methods {
if data, ok := input[method]; ok {
methodData = data
found = true
break
}
}
if !found {
return emptySlice
}
parameters, ok := post.(map[string]interface{})
parameters, ok := methodData.(map[string]interface{})
if !ok {
return emptySlice
}
@@ -30,7 +42,47 @@ func getParameters(input map[string]interface{}) []interface{} {
if !ok {
return emptySlice
}
// Check if there's a body parameter
for _, p := range res {
param, ok := p.(map[string]interface{})
if !ok {
continue
}
if param["name"] == "body" {
schema, ok := param["schema"].(map[string]interface{})
if !ok {
continue
}
properties, ok := schema["properties"].(map[string]interface{})
if !ok {
continue
}
requiredFields := make(map[string]bool)
if req, ok := schema["required"].([]interface{}); ok {
for _, r := range req {
requiredFields[r.(string)] = true
}
}
var newParams []interface{}
for name, prop := range properties {
propMap, ok := prop.(map[string]interface{})
if !ok {
continue
}
newParam := make(map[string]interface{})
newParam["name"] = name
newParam["type"] = propMap["type"]
newParam["required"] = requiredFields[name]
if propMap["type"] == "array" {
if items, ok := propMap["items"].(map[string]interface{}); ok {
newParam["items"] = items
}
}
newParams = append(newParams, newParam)
}
return newParams
}
}
return res
}
@@ -57,8 +109,10 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
requests = getRequestsMapCloudAPI()
case "cloudbroker":
requests = getRequestsMapCloudbroker()
case "sdn":
requests = getRequestsMapSDN()
default:
t.Fatalf("Wrong cloud provided, expected `cloudapi` or `cloudbroker`, got %s", cloud)
t.Fatalf("Wrong cloud provided, expected `cloudapi`, `cloudbroker` or `sdn`, got %s", cloud)
}
var dataLogs []string
@@ -96,12 +150,18 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
continue
}
name := param["name"].(string)
name, ok := param["name"].(string)
if !ok {
name = ""
}
required, ok := param["required"].(bool)
if !ok {
required = false
}
typ := p.(map[string]interface{})["type"].(string)
typ, ok := p.(map[string]interface{})["type"].(string)
if !ok {
typ = ""
}
var items string
if p.(map[string]interface{})["items"] != nil {
@@ -109,7 +169,10 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
if itemsTemp != nil {
itemsType := itemsTemp.(map[string]interface{})["type"]
if itemsType != nil {
items = itemsType.(string)
items, ok = itemsType.(string)
if !ok {
items = ""
}
}
}
}
@@ -143,7 +206,7 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
}
if len(requests) != i {
msg := fmt.Sprintf("Amount of structure checked (%d) is not the same as amount of platform requests available (%d), please check getRequestsMapCloudAPI func in code.",
msg := fmt.Sprintf("Amount of structure checked (%d) is not the same as amount of platform requests available (%d), please check getRequests func in code.",
i, len(requests))
t.Error(msg)
dataLogs = append(dataLogs, msg)