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

@@ -17,12 +17,15 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/lb"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/locations"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
securitygroup "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/security_group"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/sep"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/stack"
storagepolicy "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/storage_policy"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/tasks"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/trunk"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/vins"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/zone"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
account_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
audit_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
@@ -39,8 +42,10 @@ import (
node_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/node"
pcidevice_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice"
rg_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
securitygroup_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/security_group"
sep_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/sep"
stack_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
storagepolicy_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/storage_policy"
tasks_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/tasks"
trunk_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/trunk"
vins_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
@@ -301,6 +306,46 @@ func TestGetListCloudAPI(t *testing.T) {
}
getResult("Stack list", bytes, stack.ListStacks{}, t)
// Storage policy
// List
bytes, err = client.CloudAPI().StoragePolicy().ListRaw(context.Background(), storagepolicy.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Storage policy list", bytes, storagepolicy.ListStoragePolicies{}, t)
// Get
listStoragePolicies, _ := client.CloudAPI().StoragePolicy().List(context.Background(), storagepolicy.ListRequest{})
if len(listStoragePolicies.Data) > 0 {
id := listStoragePolicies.Data[0].ID
bytes, err = client.CloudAPI().StoragePolicy().GetRaw(context.Background(), storagepolicy.GetRequest{StoragePolicyID: id})
if err != nil {
t.Error(err)
}
getResult("Storage policy get", bytes, storagepolicy.InfoStoragePolicy{}, t)
} else {
t.Errorf("Can not test Storage policy get because Storage policy list is empty")
}
// Security group
// List
bytes, err = client.CloudAPI().SecurityGroup().ListRaw(context.Background(), securitygroup.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Security group list", bytes, securitygroup.ListSecurityGroups{}, t)
// Get
listSecurityGroups, _ := client.CloudAPI().SecurityGroup().List(context.Background(), securitygroup.ListRequest{})
if len(listSecurityGroups.Data) > 0 {
id := listSecurityGroups.Data[0].ID
bytes, err = client.CloudAPI().SecurityGroup().GetRaw(context.Background(), securitygroup.GetRequest{SecurityGroupID: id})
if err != nil {
t.Error(err)
}
getResult("Security group get", bytes, securitygroup.RecordSecurityGroup{}, t)
} else {
t.Errorf("Can not test Security group get because Security group list is empty")
}
// Tasks
// List
bytes, err = client.CloudAPI().Tasks().ListRaw(context.Background(), tasks.ListRequest{})
@@ -681,6 +726,26 @@ func TestGetListCloudbroker(t *testing.T) {
t.Errorf("Can not test RG get because RG list is empty")
}
// Security group
// List
bytes, err = client.CloudBroker().SecurityGroup().ListRaw(context.Background(), securitygroup_cb.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Security group list", bytes, securitygroup_cb.ListSecurityGroups{}, t)
// Get
listSecurityGroups, _ := client.CloudBroker().SecurityGroup().List(context.Background(), securitygroup_cb.ListRequest{})
if len(listSecurityGroups.Data) > 0 {
id := listSecurityGroups.Data[0].ID
bytes, err = client.CloudBroker().SecurityGroup().GetRaw(context.Background(), securitygroup_cb.GetRequest{SecurityGroupID: id})
if err != nil {
t.Error(err)
}
getResult("Security group get", bytes, securitygroup_cb.RecordSecurityGroup{}, t)
} else {
t.Errorf("Can not test Security group get because Security group list is empty")
}
// SEP
// List
bytes, err = client.CloudBroker().SEP().ListRaw(context.Background(), sep_cb.ListRequest{})
@@ -727,6 +792,26 @@ func TestGetListCloudbroker(t *testing.T) {
t.Errorf("Can not test Stack get because Stack list is empty")
}
// Storage policy
// List
bytes, err = client.CloudBroker().StoragePolicy().ListRaw(context.Background(), storagepolicy_cb.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Storage policy list", bytes, storagepolicy_cb.ListStoragePolicies{}, t)
// Get
listStoragePolicies, _ := client.CloudBroker().StoragePolicy().List(context.Background(), storagepolicy_cb.ListRequest{})
if len(listStoragePolicies.Data) > 0 {
id := listStoragePolicies.Data[0].ID
bytes, err = client.CloudBroker().StoragePolicy().GetRaw(context.Background(), storagepolicy_cb.GetRequest{StoragePolicyID: id})
if err != nil {
t.Error(err)
}
getResult("Storage policy get", bytes, storagepolicy_cb.InfoStoragePolicy{}, t)
} else {
t.Errorf("Can not test Storage policy get because Storage policy list is empty")
}
// Tasks
// List
bytes, err = client.CloudBroker().Tasks().ListRaw(context.Background(), tasks_cb.ListRequest{})
@@ -796,6 +881,40 @@ func TestGetListCloudbroker(t *testing.T) {
}
}
// TestGetListSDNAPI tests platforms responses vs. json tags of golang structures in cloudapi get/list methods
func TestGetListSDNAPI(t *testing.T) {
var bytes []byte
var err error
client, err := getClient()
if err != nil {
t.Fatalf("Cannot get client: %v", err)
}
// AccessGroups
// List
bytes, err = client.SDN().AccessGroups().ListRaw(context.Background(), acsgroups.ListGroupsRequest{})
if err != nil {
t.Error(err)
}
getResult("access groups list", bytes, acsgroups.AccessGroup{}, t)
// Users AccessGroups
// list
listAcsGroups, _ := client.SDN().AccessGroups().List(context.Background(), acsgroups.ListGroupsRequest{})
if len(listAcsGroups.AccessGroups) > 0 {
id := listAcsGroups.AccessGroups[0].ID
bytes, err = client.SDN().AccessGroups().UserListRaw(context.Background(), acsgroups.UsersListRequest{AccessGroupID: id})
if err != nil {
t.Error(err)
}
getResult("access groups users list", bytes, acsgroups.User{}, t)
} else {
t.Errorf("Can not test users get because acs groups list is empty")
}
}
// TestRequestsCloudAPI tests platform requests vs. golang request structures in sdk for cloudapi requests
func TestRequestsCloudAPI(t *testing.T) {
bytes := getBytesFromJSON("input.json", t)
@@ -808,6 +927,11 @@ func TestRequestsCloudbroker(t *testing.T) {
getErrorsFromJSON(bytes, t, "cloudbroker")
}
func TestRequestsSDN(t *testing.T) {
bytes := getBytesFromJSON("input.json", t)
getErrorsFromJSON(bytes, t, "sdn")
}
// TestGetAllPaths tests if platform has any handlers that golang sdk doesn't. In this case, list of missing handlers is provided.
// Note that DEPRECATED_GROUPS stores list of groups that are considered deprecated. You can add additional grops to DEPRECATED_GROUPS if required.
func TestGetAllPaths(t *testing.T) {
@@ -839,8 +963,9 @@ func TestGetAllPaths(t *testing.T) {
caTestUrls := getRequestsMapCloudAPI()
cbTestUrls := getRequestsMapCloudbroker()
sdnTestUrls := getRequestsMapSDN()
urlsInTest := make([]string, len(caTestUrls)+len(cbTestUrls))
urlsInTest := make([]string, len(caTestUrls)+len(cbTestUrls)+len(sdnTestUrls))
i := 0
for k := range caTestUrls {
@@ -851,6 +976,10 @@ func TestGetAllPaths(t *testing.T) {
urlsInTest[i] = k
i++
}
for k := range sdnTestUrls {
urlsInTest[i] = k
i++
}
missingUrls = getMissingDecortUrls(jsonUrls, urlsInTest)
if len(missingUrls) > 0 {