This commit is contained in:
2024-05-31 13:35:39 +03:00
parent e7c968797b
commit 3393934456
65 changed files with 905 additions and 393 deletions

View File

@@ -17,7 +17,11 @@
1. Тесты находятся по директории `decort-sdk/tests/platform_upgrade`
2. Внутри директории нужно создать и заполнить файл `.env` по аналогии с `.env.template` для доступа к платформе
3. Внутри директории нужно создать и заполнить файл `input.json`, содержащий json с раздела [POST /system/docgenerator/prepareCatalog](https://delta.qa.loc/system/ActorApi?group=system#!/system__docgenerator/post_system_docgenerator_prepareCatalog) (для получения json нажать кнопку Try it Out!) - требуется только для тестов запросов
3. Внутри директории нужно создать и заполнить файл `input.json`, содержащий json с раздела [POST /system/docgenerator/prepareCatalog](https://delta.qa.loc/system/ActorApi?group=system#!/system__docgenerator/post_system_docgenerator_prepareCatalog) (для получения json нажать кнопку Try it Out!) - требуется только для тестов запросов и тестов API методов
Примечание: тесты можно запускать напрямую методами среды разработки либо из командной строки из нужной директории, например командой `go test -v -run <TestName>`, где `<TestName>` - название запускаемого теста.
Примечание 2: все тесты, кроме `TestGetAllPaths` при первом запуске генерируют фал `.log`. При каждом последующем запуске результаты вывода сравниваются с файлом и в случае, если они одинаковы, то в консоль будет выведено `All lines match the log file.`. В противном случае будут выведены различающиеся строки.
## Тесты Raw методов (Get, List)
@@ -90,7 +94,7 @@ FAIL
## Тесты API методов
Запустить тест `TestGetAllPaths` в `decort-sdk/tests/platform_upgrade/cloud_test.go`
При наличии подсвеченных ошибок, проверить, что указанные методы API не являются устаревшими (deprecated). В противном случе добавить устаревшие методы в переменную `DEPRECATED_GROUPS` по адресу `decort-sdk/tests/platform_upgrade/utils_url.go`.
При наличии подсвеченных ошибок, проверить, что указанные методы API не являются устаревшими (deprecated). В противном случае добавить устаревшие методы в переменную `DEPRECATED_GROUPS` по адресу `decort-sdk/tests/platform_upgrade/utils_url.go`.
Пример вывода:
```go

View File

@@ -50,13 +50,16 @@ func TestGetListCloudAPI(t *testing.T) {
t.Fatalf("Cannot get client: %v", err)
}
const logFileName = "test_get_list_cloudAPI.log"
var testLogs []string
// Account
// List
bytes, err = client.CloudAPI().Account().ListRaw(context.Background(), account.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Account list", bytes, account.ListAccounts{}, t)
testLogs = append(testLogs, getResult("Account list", bytes, account.ListAccounts{}, t))
// Get
listAcc, _ := client.CloudAPI().Account().List(context.Background(), account.ListRequest{})
if len(listAcc.Data) > 0 {
@@ -65,7 +68,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Account get", bytes, account.RecordAccount{}, t)
testLogs = append(testLogs, getResult("Account get", bytes, account.RecordAccount{}, t))
} else {
t.Errorf("Can not test Account get because account list is empty")
}
@@ -76,7 +79,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Bservice list", bytes, bservice.ListBasicServices{}, t)
testLogs = append(testLogs, getResult("Bservice list", bytes, bservice.ListBasicServices{}, t))
// Get
listBServ, _ := client.CloudAPI().BService().List(context.Background(), bservice.ListRequest{})
if len(listBServ.Data) > 0 {
@@ -85,7 +88,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Bservice get", bytes, bservice.RecordBasicService{}, t)
testLogs = append(testLogs, getResult("Bservice get", bytes, bservice.RecordBasicService{}, t))
} else {
t.Errorf("Can not test Bservice get because bservice list is empty")
}
@@ -96,7 +99,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Compute list", bytes, compute.ListComputes{}, t)
testLogs = append(testLogs, getResult("Compute list", bytes, compute.ListComputes{}, t))
// Get
listComp, _ := client.CloudAPI().Compute().List(context.Background(), compute.ListRequest{})
if len(listComp.Data) > 0 {
@@ -105,7 +108,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Compute get", bytes, compute.RecordCompute{}, t)
testLogs = append(testLogs, getResult("Compute get", bytes, compute.RecordCompute{}, t))
} else {
t.Errorf("Can not test Compute get because compute list is empty")
}
@@ -116,7 +119,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Disk list", bytes, disks.ListDisks{}, t)
testLogs = append(testLogs, getResult("Disk list", bytes, disks.ListDisks{}, t))
// Get
listDisk, _ := client.CloudAPI().Disks().List(context.Background(), disks.ListRequest{})
if len(listDisk.Data) > 0 {
@@ -125,7 +128,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Disk get", bytes, disks.RecordDisk{}, t)
testLogs = append(testLogs, getResult("Disk get", bytes, disks.RecordDisk{}, t))
} else {
t.Errorf("Can not test Disk get because disk list is empty")
}
@@ -136,7 +139,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("ExtNet list", bytes, extnet.ListExtNets{}, t)
testLogs = append(testLogs, getResult("ExtNet list", bytes, extnet.ListExtNets{}, t))
// Get
listExtNet, _ := client.CloudAPI().ExtNet().List(context.Background(), extnet.ListRequest{})
if len(listExtNet.Data) > 0 {
@@ -145,7 +148,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("ExtNet get", bytes, extnet.RecordExtNet{}, t)
testLogs = append(testLogs, getResult("ExtNet get", bytes, extnet.RecordExtNet{}, t))
} else {
t.Errorf("Can not test ExtNet get because listExtNet list is empty")
}
@@ -156,7 +159,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("FLIPGroup list", bytes, flipgroup.ListFLIPGroups{}, t)
testLogs = append(testLogs, getResult("FLIPGroup list", bytes, flipgroup.ListFLIPGroups{}, t))
// Get
listFG, _ := client.CloudAPI().FLIPGroup().List(context.Background(), flipgroup.ListRequest{})
if len(listFG.Data) > 0 {
@@ -165,7 +168,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("FLIPGroup get", bytes, flipgroup.RecordFLIPGroup{}, t)
testLogs = append(testLogs, getResult("FLIPGroup get", bytes, flipgroup.RecordFLIPGroup{}, t))
} else {
t.Errorf("Can not test FLIPGroup get because flipgroup list is empty")
}
@@ -176,7 +179,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Image list", bytes, image.ListImages{}, t)
testLogs = append(testLogs, getResult("Image list", bytes, image.ListImages{}, t))
// Get
listImg, _ := client.CloudAPI().Image().List(context.Background(), image.ListRequest{})
if len(listImg.Data) > 0 {
@@ -185,7 +188,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Image get", bytes, image.RecordImage{}, t)
testLogs = append(testLogs, getResult("Image get", bytes, image.RecordImage{}, t))
} else {
t.Errorf("Can not test Image get because Image list is empty")
}
@@ -196,7 +199,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8CI list", bytes, k8ci.ListK8CI{}, t)
testLogs = append(testLogs, getResult("K8CI list", bytes, k8ci.ListK8CI{}, t))
// Get
listk8ci, _ := client.CloudAPI().K8CI().List(context.Background(), k8ci.ListRequest{})
if len(listk8ci.Data) > 0 {
@@ -205,7 +208,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8CI get", bytes, k8ci.RecordK8CI{}, t)
testLogs = append(testLogs, getResult("K8CI get", bytes, k8ci.RecordK8CI{}, t))
} else {
t.Errorf("Can not test K8CI get because K8CI list is empty")
}
@@ -216,7 +219,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8S list", bytes, k8s.ListK8SClusters{}, t)
testLogs = append(testLogs, getResult("K8S list", bytes, k8s.ListK8SClusters{}, t))
// Get
listk8s, _ := client.CloudAPI().K8S().List(context.Background(), k8s.ListRequest{})
if len(listk8s.Data) > 0 {
@@ -225,7 +228,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8S get", bytes, k8s.RecordK8S{}, t)
testLogs = append(testLogs, getResult("K8S get", bytes, k8s.RecordK8S{}, t))
} else {
t.Errorf("Can not test K8S get because K8S list is empty")
}
@@ -236,7 +239,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("LB list", bytes, lb.ListLB{}, t)
testLogs = append(testLogs, getResult("LB list", bytes, lb.ListLB{}, t))
// Get
listLB, _ := client.CloudAPI().LB().List(context.Background(), lb.ListRequest{})
if len(listLB.Data) > 0 {
@@ -245,7 +248,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("LB get", bytes, lb.RecordLB{}, t)
testLogs = append(testLogs, getResult("LB get", bytes, lb.RecordLB{}, t))
} else {
t.Errorf("Can not test LB get because LB list is empty")
}
@@ -256,7 +259,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Locations list", bytes, locations.ListLocations{}, t)
testLogs = append(testLogs, getResult("Locations list", bytes, locations.ListLocations{}, t))
// RG
// List
@@ -264,7 +267,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("RG list", bytes, rg.ListResourceGroups{}, t)
testLogs = append(testLogs, getResult("RG list", bytes, rg.ListResourceGroups{}, t))
// Get
listRG, _ := client.CloudAPI().RG().List(context.Background(), rg.ListRequest{})
if len(listRG.Data) > 0 {
@@ -273,7 +276,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("RG get", bytes, rg.RecordResourceGroup{}, t)
testLogs = append(testLogs, getResult("RG get", bytes, rg.RecordResourceGroup{}, t))
} else {
t.Errorf("Can not test RG get because RG list is empty")
}
@@ -284,7 +287,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Sizes list", bytes, sizes.ListSizes{}, t)
testLogs = append(testLogs, getResult("Sizes list", bytes, sizes.ListSizes{}, t))
// Stack
// List
@@ -292,7 +295,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Stack list", bytes, stack.ListStacks{}, t)
testLogs = append(testLogs, getResult("Stack list", bytes, stack.ListStacks{}, t))
// Tasks
// List
@@ -300,7 +303,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Tasks list", bytes, tasks.ListTasks{}, t)
testLogs = append(testLogs, getResult("Tasks list", bytes, tasks.ListTasks{}, t))
// Get
listTasks, _ := client.CloudAPI().Tasks().List(context.Background(), tasks.ListRequest{})
if len(listTasks.Data) > 0 {
@@ -309,7 +312,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Tasks get", bytes, tasks.RecordAsyncTask{}, t)
testLogs = append(testLogs, getResult("Tasks get", bytes, tasks.RecordAsyncTask{}, t))
} else {
t.Errorf("Can not test Tasks get because Tasks list is empty")
}
@@ -320,7 +323,7 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("VINS list", bytes, vins.ListVINS{}, t)
testLogs = append(testLogs, getResult("VINS list", bytes, vins.ListVINS{}, t))
// Get
listVINS, _ := client.CloudAPI().VINS().List(context.Background(), vins.ListRequest{})
if len(listVINS.Data) > 0 {
@@ -329,10 +332,12 @@ func TestGetListCloudAPI(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("VINS get", bytes, vins.RecordVINS{}, t)
testLogs = append(testLogs, getResult("VINS get", bytes, vins.RecordVINS{}, t))
} else {
t.Errorf("Can not test VINS get because VINS list is empty")
}
compareLogs(logFileName, testLogs, t, "get")
}
// WARNING: not working correctly due to inclusions of tagless structures in cloudbroker
@@ -345,13 +350,15 @@ func TestGetListCloudbroker(t *testing.T) {
t.Fatalf("Cannot get client: %v", err)
}
const logFileName = "test_get_list_cloudbroker.log"
var testLogs = make([]string, 0)
// Account
// List
bytes, err = client.CloudBroker().Account().ListRaw(context.Background(), account_cb.ListRequest{})
if err != nil {
t.Error(err)
}
getResult("Account list", bytes, account_cb.ListAccounts{}, t)
testLogs = append(testLogs, getResult("Account list", bytes, account_cb.ListAccounts{}, t))
// Get
listAcc, _ := client.CloudBroker().Account().List(context.Background(), account_cb.ListRequest{})
if len(listAcc.Data) > 0 {
@@ -360,7 +367,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Account get", bytes, account_cb.RecordAccount{}, t)
testLogs = append(testLogs, getResult("Account get", bytes, account_cb.RecordAccount{}, t))
} else {
t.Errorf("Can not test Account get because account list is empty")
}
@@ -371,7 +378,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Audit list", bytes, audit_cb.ListAudits{}, t)
testLogs = append(testLogs, getResult("Audit list", bytes, audit_cb.ListAudits{}, t))
// Get
listAudits, _ := client.CloudBroker().Audit().List(context.Background(), audit_cb.ListRequest{})
if len(listAudits.Data) > 0 {
@@ -380,7 +387,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Audit get", bytes, audit_cb.RecordAudit{}, t)
testLogs = append(testLogs, getResult("Audit get", bytes, audit_cb.RecordAudit{}, t))
} else {
t.Errorf("Can not test Audit get because Audit list is empty")
}
@@ -391,7 +398,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Compute list", bytes, compute_cb.ListComputes{}, t)
testLogs = append(testLogs, getResult("Compute list", bytes, compute_cb.ListComputes{}, t))
// Get
listComp, _ := client.CloudBroker().Compute().List(context.Background(), compute_cb.ListRequest{})
if len(listComp.Data) > 0 {
@@ -400,7 +407,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Compute get", bytes, compute_cb.RecordCompute{}, t)
testLogs = append(testLogs, getResult("Compute get", bytes, compute_cb.RecordCompute{}, t))
} else {
t.Errorf("Can not test Compute get because compute list is empty")
}
@@ -411,7 +418,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Disk list", bytes, disks_cb.ListDisks{}, t)
testLogs = append(testLogs, getResult("Disk list", bytes, disks_cb.ListDisks{}, t))
// Get
listDisk, _ := client.CloudBroker().Disks().List(context.Background(), disks_cb.ListRequest{})
if len(listDisk.Data) > 0 {
@@ -420,7 +427,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Disk get", bytes, disks_cb.RecordDisk{}, t)
testLogs = append(testLogs, getResult("Disk get", bytes, disks_cb.RecordDisk{}, t))
} else {
t.Errorf("Can not test Disk get because disk list is empty")
}
@@ -431,7 +438,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("ExtNet list", bytes, extnet_cb.ListExtNet{}, t)
testLogs = append(testLogs, getResult("ExtNet list", bytes, extnet_cb.ListExtNet{}, t))
// Get
listExtNet, _ := client.CloudBroker().ExtNet().List(context.Background(), extnet_cb.ListRequest{})
if len(listExtNet.Data) > 0 {
@@ -440,7 +447,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("ExtNet get", bytes, extnet_cb.RecordExtNet{}, t)
testLogs = append(testLogs, getResult("ExtNet get", bytes, extnet_cb.RecordExtNet{}, t))
} else {
t.Errorf("Can not test ExtNet get because listExtNet list is empty")
}
@@ -451,7 +458,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("FLIPGroup list", bytes, flipgroup_cb.ListFLIPGroups{}, t)
testLogs = append(testLogs, getResult("FLIPGroup list", bytes, flipgroup_cb.ListFLIPGroups{}, t))
// Get
listFG, _ := client.CloudBroker().FLIPGroup().List(context.Background(), flipgroup_cb.ListRequest{})
if len(listFG.Data) > 0 {
@@ -460,7 +467,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("FLIPGroup get", bytes, flipgroup_cb.RecordFLIPGroup{}, t)
testLogs = append(testLogs, getResult("FLIPGroup get", bytes, flipgroup_cb.RecordFLIPGroup{}, t))
} else {
t.Errorf("Can not test FLIPGroup get because flipgroup list is empty")
}
@@ -471,7 +478,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Grid list", bytes, grid_cb.ListGrids{}, t)
testLogs = append(testLogs, getResult("Grid list", bytes, grid_cb.ListGrids{}, t))
// Get
listGrid, _ := client.CloudBroker().Grid().List(context.Background(), grid_cb.ListRequest{})
if len(listGrid.Data) > 0 {
@@ -480,7 +487,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Grid get", bytes, grid_cb.RecordGrid{}, t)
testLogs = append(testLogs, getResult("Grid get", bytes, grid_cb.RecordGrid{}, t))
} else {
t.Errorf("Can not test Grid get because Grid list is empty")
}
@@ -491,7 +498,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Image list", bytes, image_cb.ListImages{}, t)
testLogs = append(testLogs, getResult("Image list", bytes, image_cb.ListImages{}, t))
// Get
listImg, _ := client.CloudBroker().Image().List(context.Background(), image_cb.ListRequest{})
if len(listImg.Data) > 0 {
@@ -500,7 +507,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Image get", bytes, image_cb.RecordImage{}, t)
testLogs = append(testLogs, getResult("Image get", bytes, image_cb.RecordImage{}, t))
} else {
t.Errorf("Can not test Image get because Image list is empty")
}
@@ -511,7 +518,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8CI list", bytes, k8ci_cb.ListK8CI{}, t)
testLogs = append(testLogs, getResult("K8CI list", bytes, k8ci_cb.ListK8CI{}, t))
// Get
listk8ci, _ := client.CloudBroker().K8CI().List(context.Background(), k8ci_cb.ListRequest{})
if len(listk8ci.Data) > 0 {
@@ -520,7 +527,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8CI get", bytes, k8ci_cb.RecordK8CI{}, t)
testLogs = append(testLogs, getResult("K8CI get", bytes, k8ci_cb.RecordK8CI{}, t))
} else {
t.Errorf("Can not test K8CI get because K8CI list is empty")
}
@@ -531,7 +538,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8S list", bytes, k8s_cb.ListK8S{}, t)
testLogs = append(testLogs, getResult("K8S list", bytes, k8s_cb.ListK8S{}, t))
// Get
listk8s, _ := client.CloudBroker().K8S().List(context.Background(), k8s_cb.ListRequest{})
if len(listk8s.Data) > 0 {
@@ -540,7 +547,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("K8S get", bytes, k8s_cb.RecordK8S{}, t)
testLogs = append(testLogs, getResult("K8S get", bytes, k8s_cb.RecordK8S{}, t))
} else {
t.Errorf("Can not test K8S get because K8S list is empty")
}
@@ -551,7 +558,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("LB list", bytes, lb_cb.ListLB{}, t)
testLogs = append(testLogs, getResult("LB list", bytes, lb_cb.ListLB{}, t))
// Get
listLB, _ := client.CloudBroker().LB().List(context.Background(), lb_cb.ListRequest{})
if len(listLB.Data) > 0 {
@@ -560,7 +567,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("LB get", bytes, lb_cb.RecordLB{}, t)
testLogs = append(testLogs, getResult("LB get", bytes, lb_cb.RecordLB{}, t))
} else {
t.Errorf("Can not test LB get because LB list is empty")
}
@@ -571,7 +578,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Pcidevice list", bytes, pcidevice_cb.ListPCIDevices{}, t)
testLogs = append(testLogs, getResult("Pcidevice list", bytes, pcidevice_cb.ListPCIDevices{}, t))
// RG
// List
@@ -579,7 +586,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("RG list", bytes, rg_cb.ListRG{}, t)
testLogs = append(testLogs, getResult("RG list", bytes, rg_cb.ListRG{}, t))
// Get
listRG, _ := client.CloudBroker().RG().List(context.Background(), rg_cb.ListRequest{})
if len(listRG.Data) > 0 {
@@ -588,7 +595,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("RG get", bytes, rg_cb.RecordRG{}, t)
testLogs = append(testLogs, getResult("RG get", bytes, rg_cb.RecordRG{}, t))
} else {
t.Errorf("Can not test RG get because RG list is empty")
}
@@ -599,7 +606,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("SEP list", bytes, sep_cb.ListSEP{}, t)
testLogs = append(testLogs, getResult("SEP list", bytes, sep_cb.ListSEP{}, t))
// Get
listSEP, _ := client.CloudBroker().SEP().List(context.Background(), sep_cb.ListRequest{})
if len(listSEP.Data) > 0 {
@@ -608,7 +615,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("SEP get", bytes, sep_cb.RecordSEP{}, t)
testLogs = append(testLogs, getResult("SEP get", bytes, sep_cb.RecordSEP{}, t))
} else {
t.Errorf("Can not test SEP get because SEP list is empty")
}
@@ -619,7 +626,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Stack list", bytes, stack_cb.ListStacks{}, t)
testLogs = append(testLogs, getResult("Stack list", bytes, stack_cb.ListStacks{}, t))
// Get
listStack, _ := client.CloudBroker().Stack().List(context.Background(), stack_cb.ListRequest{})
if len(listStack.Data) > 0 {
@@ -628,7 +635,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Stack get", bytes, stack_cb.InfoStack{}, t)
testLogs = append(testLogs, getResult("Stack get", bytes, stack_cb.InfoStack{}, t))
} else {
t.Errorf("Can not test Stack get because Stack list is empty")
}
@@ -639,7 +646,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("Tasks list", bytes, tasks_cb.ListTasks{}, t)
testLogs = append(testLogs, getResult("Tasks list", bytes, tasks_cb.ListTasks{}, t))
// VINS
// List
@@ -647,7 +654,7 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("VINS list", bytes, vins_cb.ListVINS{}, t)
testLogs = append(testLogs, getResult("VINS list", bytes, vins_cb.ListVINS{}, t))
// Get
listVINS, _ := client.CloudBroker().VINS().List(context.Background(), vins_cb.ListRequest{})
if len(listVINS.Data) > 0 {
@@ -656,10 +663,11 @@ func TestGetListCloudbroker(t *testing.T) {
if err != nil {
t.Error(err)
}
getResult("VINS get", bytes, vins_cb.RecordVINS{}, t)
testLogs = append(testLogs, getResult("VINS get", bytes, vins_cb.RecordVINS{}, t))
} else {
t.Errorf("Can not test VINS get because VINS list is empty")
}
compareLogs(logFileName, testLogs, t, "get")
}
// TestRequestsCloudAPI tests platform requests vs. golang request structures in sdk for cloudapi requests

View File

@@ -557,6 +557,7 @@ func getRequestsMapCloudbroker() map[string]interface{} {
"/cloudbroker/disks/create": disks_cb.CreateRequest{},
"/cloudbroker/disks/delete": disks_cb.DeleteRequest{},
"/cloudbroker/disks/deleteDisks": disks_cb.DeleteDisksRequest{},
"/cloudbroker/disks/depresent": disks_cb.DepresentRequest{},
"/cloudbroker/disks/fromPlatformDisk": disks_cb.FromPlatformDiskRequest{},
"/cloudbroker/disks/get": disks_cb.GetRequest{},
"/cloudbroker/disks/limitIO": disks_cb.LimitIORequest{},
@@ -565,6 +566,7 @@ func getRequestsMapCloudbroker() map[string]interface{} {
"/cloudbroker/disks/listTypes": disks_cb.ListTypesRequest{},
"/cloudbroker/disks/listUnattached": disks_cb.ListUnattachedRequest{},
"/cloudbroker/disks/rename": disks_cb.RenameRequest{},
"/cloudbroker/disks/present": disks_cb.PresentRequest{},
"/cloudbroker/disks/replicate": disks_cb.ReplicateRequest{},
"/cloudbroker/disks/replicationResume": disks_cb.ReplicationResumeRequest{},
"/cloudbroker/disks/replicationReverse": disks_cb.ReplicationReverseRequest{},

View File

@@ -0,0 +1,31 @@
[
"Account list: OK",
"Account get: OK",
"",
"Bservice get: OK",
"Compute list: \nPlatform has these fields that golang struct doesn't: [lb mgmt_target mgmt_mac mgmt_slot]\n",
"Compute get: \nPlatform has these fields that golang struct doesn't: [mgmt_target mgmt_mac mgmt_slot lb]\n",
"Disk list: OK",
"Disk get: OK",
"",
"ExtNet get: OK",
"FLIPGroup list: OK",
"",
"",
"Image get: \nPlatform has these fields that golang struct doesn't: [12]\n",
"K8CI list: OK",
"",
"K8S list: OK",
"K8S get: OK",
"LB list: \nPlatform has these fields that golang struct doesn't: [fs.inotify.max_queued_events kernel.kptr_restrict net.ipv4.tcp_congestion_control]\n",
"LB get: \nPlatform has these fields that golang struct doesn't: [kernel.kptr_restrict net.ipv4.tcp_congestion_control fs.inotify.max_queued_events]\n",
"Locations list: OK",
"RG list: OK",
"",
"Sizes list: OK",
"",
"Tasks list: \nPlatform has these fields that golang struct doesn't: [completed guid stage updateTime updatedTime auditId error log status]\n",
"Tasks get: \nPlatform has these fields that golang struct doesn't: [updatedTime completed error updateTime auditId stage status log]\n",
"",
"VINS get: OK"
]

View File

@@ -0,0 +1,34 @@
[
"Account list: OK",
"Account get: OK",
"",
"Audit get: OK",
"Compute list: \nPlatform has these fields that golang struct doesn't: [disks]\n",
"Compute get: OK",
"Disk list: \nPlatform has these fields that golang struct doesn't: [machineId machineName sepType devicename]\n",
"Disk get: \nPlatform has these fields that golang struct doesn't: [devicename sepType updatedBy]\n",
"ExtNet list: OK",
"ExtNet get: OK",
"FLIPGroup list: OK",
"",
"Grid list: \nPlatform has these fields that golang struct doesn't: [1 90 380 1 90 380]\n",
"Grid get: OK",
"Image list: OK",
"Image get: OK",
"K8CI list: \nPlatform has these fields that golang struct doesn't: [createdTime]\n",
"K8CI get: OK",
"K8S list: OK",
"K8S get: OK",
"LB list: OK",
"LB get: OK",
"Pcidevice list: OK",
"RG list: OK",
"RG get: OK",
"SEP list: \nPlatform has these fields that golang struct doesn't: [protocol disk_max_size format name name_prefix pools]\n",
"SEP get: \nPlatform has these fields that golang struct doesn't: [format name name_prefix pools protocol disk_max_size]\n",
"Stack list: OK",
"Stack get: OK",
"Tasks list: \nPlatform has these fields that golang struct doesn't: [stage status error log auditId completed updateTime guid]\n",
"",
"VINS get: \nPlatform has these fields that golang struct doesn't: [computes config config config]\n"
]

View File

@@ -0,0 +1,14 @@
[
"Path /cloudapi/compute/antiAffinityRuleAdd has following errors: [Field value has different required parameters on the platform and in golang structure]",
"Path /cloudapi/user/setData has following errors: [Field data has different required parameters on the platform and in golang structure]",
"Path /cloudapi/compute/affinityRuleRemove has following errors: [Field value has different required parameters on the platform and in golang structure]",
"Path /cloudapi/compute/createTemplate has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field asyncMode that golang structure doesn't]",
"Path /cloudapi/k8s/create has following errors: [Field oidcCertificate has different type parameters on the platform and in golang structure]",
"Path /cloudapi/disks/fromPlatformDisk has following errors: [Platform (14) and golang structure (13) have different amount of fields. Field drivers has different type parameters on the platform and in golang structure Platform has field asyncMode that golang structure doesn't]",
"Path /cloudapi/compute/affinityRuleAdd has following errors: [Field value has different required parameters on the platform and in golang structure]",
"Path /cloudapi/compute/antiAffinityRuleRemove has following errors: [Field value has different required parameters on the platform and in golang structure]",
"Path /cloudapi/compute/createTemplateFromBlank has following errors: [Platform (11) and golang structure (10) have different amount of fields. Platform has field asyncMode that golang structure doesn't]",
"Path /cloudapi/lb/create has following errors: [Field extnetId has different required parameters on the platform and in golang structure Field vinsId has different required parameters on the platform and in golang structure]",
"Path /cloudapi/image/list has following errors: [Field size has different type parameters on the platform and in golang structure]",
"Path /cloudapi/compute/snapshotDelete has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field asyncMode that golang structure doesn't]"
]

View File

@@ -0,0 +1 @@
["Path /cloudbroker/compute/createTemplate has following errors: [Platform (4) and golang structure (3) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/backup/createDisksBackup has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/compute/affinityRuleAdd has following errors: [Field value has different required parameters on the platform and in golang structure]","Path /cloudbroker/apiaccess/update has following errors: [Platform has field apis that golang structure doesn't]","Path /cloudbroker/compute/antiAffinityRuleRemove has following errors: [Field value has different required parameters on the platform and in golang structure]","Path /cloudbroker/compute/snapshotDelete has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/backup/restoreDiskFromBackup has following errors: [Platform (5) and golang structure (4) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/backup/createDiskBackup has following errors: [Platform (4) and golang structure (3) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/compute/createTemplateFromBlank has following errors: [Platform (11) and golang structure (10) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/account/setCpuAllocationRatio has following errors: [Field ratio has different required parameters on the platform and in golang structure]","Path /cloudbroker/disks/fromPlatformDisk has following errors: [Platform (14) and golang structure (13) have different amount of fields. Field drivers has different type parameters on the platform and in golang structure Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/lb/create has following errors: [Field extnetId has different required parameters on the platform and in golang structure Field vinsId has different required parameters on the platform and in golang structure]","Path /cloudbroker/stack/setCpuAllocationRatio has following errors: [Field ratio has different required parameters on the platform and in golang structure]","Path /cloudbroker/backup/deleteDiskBackup has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/image/updateNodes has following errors: [Field enabledStacks has different type parameters on the platform and in golang structure]","Path /cloudbroker/stack/setMemAllocationRatio has following errors: [Field ratio has different required parameters on the platform and in golang structure]","Path /cloudbroker/compute/antiAffinityRuleAdd has following errors: [Field value has different required parameters on the platform and in golang structure]","Path /cloudbroker/k8s/create has following errors: [Field oidcCertificate has different type parameters on the platform and in golang structure]","Path /cloudbroker/backup/restoreDisksFromBackup has following errors: [Platform (3) and golang structure (2) have different amount of fields. Platform has field disks that golang structure doesn't Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/node/enable has following errors: [Platform (4) and golang structure (3) have different amount of fields. Platform has field asyncMode that golang structure doesn't]","Path /cloudbroker/compute/affinityRuleRemove has following errors: [Field value has different required parameters on the platform and in golang structure]","Path /cloudbroker/image/list has following errors: [Field size has different type parameters on the platform and in golang structure]"]

View File

@@ -56,7 +56,7 @@ func getClient() (*decort.DecortClient, error) {
}
// getResult checks how json-structure of bytes is different from golang structure and return t.Error if there are any differences.
func getResult(testName string, bytes []byte, structure any, t *testing.T) {
func getResult(testName string, bytes []byte, structure any, t *testing.T) string {
// convert bytes to map[string]interface{}
bytesMap, err := GetMapFromBytes(bytes)
if err != nil {
@@ -68,8 +68,11 @@ func getResult(testName string, bytes []byte, structure any, t *testing.T) {
// assert if they are equal
if !reflect.DeepEqual(bytesMap, structMap) {
t.Errorf(getDifference(testName, bytesMap, structMap))
var result = getDifference(testName, bytesMap, structMap)
t.Errorf(result)
return result
}
return ""
}
// getDifference tells which fields are present in bytesMap and not present in structMap and vice versa.

View File

@@ -0,0 +1,119 @@
package test
import (
"bufio"
"encoding/json"
"io"
"os"
"regexp"
"sort"
"strings"
"testing"
)
func compareLogs(logFileName string, logsData []string, t *testing.T, testType string) {
if _, err := os.Stat(logFileName); os.IsNotExist(err) {
file, err := os.Create(logFileName)
if err != nil {
t.Errorf("Failed to create log file: %v", err)
}
defer file.Close()
writer := bufio.NewWriter(file)
jsonData, err := json.MarshalIndent(logsData, "", " ")
if err != nil {
t.Errorf("Failed to marshal logsData to JSON: %v", err)
}
_, err = writer.WriteString(string(jsonData))
if err != nil {
t.Errorf("Failed to write JSON to log file: %v", err)
}
writer.Flush()
} else {
file, err := os.Open(logFileName)
if err != nil {
t.Errorf("Failed to open log file: %v", err)
}
defer file.Close()
reader := bufio.NewReader(file)
var sb strings.Builder
for {
line, err := reader.ReadString('\n')
if err != nil {
if err == io.EOF {
sb.WriteString(strings.TrimSpace(line))
break
}
t.Errorf("Error reading log file: %v", err)
return
}
sb.WriteString(strings.TrimSpace(line))
}
var fileContent = sb.String()
var fileLogsData []string
err = json.Unmarshal([]byte(fileContent), &fileLogsData)
if err != nil {
t.Errorf("Failed to unmarshal JSON from log file: %v", err)
}
if len(fileLogsData) != len(logsData) {
t.Errorf("Log data length does not match. Got: %d, Expected: %d", len(fileLogsData), len(logsData))
}
var allLinesMatch = true
switch testType {
default:
for i := range logsData {
if sortBracketsContent(fileLogsData[i]) != sortBracketsContent(logsData[i]) {
allLinesMatch = false
t.Errorf("Line %d does not match. Got: %s, Expected: %s", i+1, sortBracketsContent(fileLogsData[i]), sortBracketsContent(logsData[i]))
}
}
if allLinesMatch {
t.Log("\nAll lines match the log file.")
}
case "request":
var tmp = make(map[string]struct{})
for _, v := range fileLogsData {
if _, ok := tmp[v]; ok {
delete(tmp, v)
} else {
tmp[v] = struct{}{}
}
}
for _, v := range logsData {
if _, ok := tmp[v]; ok {
delete(tmp, v)
} else {
tmp[v] = struct{}{}
}
}
if len(tmp) == 0 {
t.Log("\nAll lines match the log file.")
return
}
for i := range tmp {
t.Errorf("Line %s does not match.", i)
}
}
}
}
func sortBracketsContent(log string) string {
re := regexp.MustCompile(`\[([^\[\]]*)\]`)
return re.ReplaceAllStringFunc(log, func(match string) string {
content := match[1 : len(match)-1]
parts := strings.Split(content, " ")
sort.Strings(parts)
return "[" + strings.Join(parts, " ") + "]"
})
}

View File

@@ -51,16 +51,21 @@ func getBytesFromJSON(fileName string, t *testing.T) []byte {
func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
var requests map[string]interface{}
var logFileName string
switch cloud {
case "cloudapi":
requests = getRequestsMapCloudAPI()
logFileName = "test_requests_cloudAPI.log"
case "cloudbroker":
requests = getRequestsMapCloudbroker()
logFileName = "test_requests_cloudbroker.log"
default:
t.Fatalf("Wrong cloud provided, expected `cloudapi` or `cloudbroker`, got %s", cloud)
}
var dataLogs []string
paths, err := getMapFromFile(bytes)
if err != nil {
t.Error(err)
@@ -131,14 +136,19 @@ func getErrorsFromJSON(bytes []byte, t *testing.T, cloud string) {
}
}
if len(errs) > 0 {
t.Errorf("Path %s has following errors: %v", k, errs)
msg := fmt.Sprintf("Path %s has following errors: %v", k, errs)
t.Error(msg)
dataLogs = append(dataLogs, msg)
}
}
if len(requests) != i {
t.Errorf("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 getRequestsMapCloudAPI func in code.",
i, len(requests))
t.Error(msg)
dataLogs = append(dataLogs, msg)
}
compareLogs(logFileName, dataLogs, t, "request")
}
// checkName checks if name field from platform has the same value as json tag in golang structure (maybe including omitempty)
@@ -211,8 +221,13 @@ func checkKind(platformType, items string, typ reflect.Type) bool {
return true
}
return false
}
}
return false
default: // for cases like dataDisks etc.
return true
}
default: // for cases like drivers etc
return true
}
}