test git
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"errors"
|
||||
|
||||
decortsdk "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
)
|
||||
|
||||
type Migrator interface {
|
||||
Migrate(ctxOrigin context.Context, vmUUID, to uint64) (bool, error)
|
||||
}
|
||||
|
||||
type migrator struct {
|
||||
cfg *Config
|
||||
client decortsdk.ClientInterface
|
||||
}
|
||||
|
||||
func NewMigrator(cfg *Config, c decortsdk.ClientInterface) Migrator {
|
||||
return &migrator{
|
||||
cfg: cfg,
|
||||
client: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *migrator) Migrate(ctxOrigin context.Context, dxVMID, nodeID uint64) (bool, error) {
|
||||
req := compute.MigrateRequest{
|
||||
ComputeID: dxVMID,
|
||||
TargetNodeID: nodeID,
|
||||
Force: false,
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctxOrigin, m.cfg.QueryTimeout)
|
||||
ok, err := m.client.CloudBroker().Compute().Migrate(ctx, req)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return false, errors.Join(err, fmt.Errorf("Migrate VM %d to Node %d", dxVMID, nodeID))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
decortsdk "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/samples/client"
|
||||
)
|
||||
|
||||
// Пример юнит тестирования на моках
|
||||
func TestClient(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
// Создаем мок инстанс интерфейса Caller
|
||||
mockCaller := decortsdk.NewMockCaller(ctrl)
|
||||
// Создаем мок инстанс интерфейса DecortClient
|
||||
mockClient := decortsdk.NewMockDecortClient(mockCaller)
|
||||
|
||||
dxVMID := uint64(100500)
|
||||
VMID := "vm-100500"
|
||||
|
||||
listComputes := &compute.ListComputes{
|
||||
Data: []compute.ItemCompute{
|
||||
{
|
||||
InfoCompute: compute.InfoCompute{
|
||||
ID: dxVMID,
|
||||
ReferenceID: VMID,
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
b, err := json.Marshal(listComputes)
|
||||
assert.NoError(t, err)
|
||||
// Подготавливаем мок для вызова метода CloudBroker().Compute().List()
|
||||
mockCaller.EXPECT().DecortApiCall(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(compute.ListRequest{})).Return(b, nil).AnyTimes()
|
||||
listComputesRet, err := mockClient.CloudBroker().Compute().List(context.Background(), compute.ListRequest{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, listComputes, listComputesRet)
|
||||
|
||||
}
|
||||
|
||||
// Пример юнит тестирования на моках
|
||||
func TestMigrator(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
// Создаем мок инстанс интерфейса Caller
|
||||
mockCaller := decortsdk.NewMockCaller(ctrl)
|
||||
// Создаем мок инстанс интерфейса interfaces.ClientInterface
|
||||
mockClient := decortsdk.NewMockDecortClient(mockCaller)
|
||||
|
||||
// Передаем мок инстанс интерфейса interfaces.ClientInterface в конструктор Migrator
|
||||
migrator := client.NewMigrator(&client.Config{QueryTimeout: time.Second}, mockClient)
|
||||
|
||||
b, err := json.Marshal(true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
dxVMID := uint64(100500)
|
||||
nodeID := uint64(100501)
|
||||
|
||||
// Записываем поведение клиента
|
||||
mockCaller.EXPECT().DecortApiCall(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Eq(compute.AsyncWrapperMigrateRequest{
|
||||
MigrateRequest: compute.MigrateRequest{
|
||||
ComputeID: dxVMID,
|
||||
TargetNodeID: nodeID,
|
||||
},
|
||||
SyncMode: true})).Return(b, nil).AnyTimes()
|
||||
|
||||
ok, err := migrator.Migrate(context.Background(), dxVMID, nodeID)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package client
|
||||
|
||||
import "time"
|
||||
|
||||
type Config struct {
|
||||
QueryTimeout time.Duration
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://bvs-delta.qa.loc:8443",
|
||||
"decortUrl": "https://delta.qa.loc",
|
||||
"domain": "dynamix",
|
||||
"token": {
|
||||
"access_token": "string_token",
|
||||
"token_type": "bearer",
|
||||
"refresh_token": "string_refresh_token",
|
||||
"expiry": "2023-11-24T12:40:27.954150524+03:00"
|
||||
},
|
||||
"retries": 5,
|
||||
"sslSkipVerify": true,
|
||||
"timeout": "5m",
|
||||
"path_cfg": "config",
|
||||
"path_token": "token",
|
||||
"timeToRefresh": 5
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
appId: <APP_ID>
|
||||
appSecret: <APP_SECRET>
|
||||
ssoUrl: https://bvs-delta.qa.loc:8443
|
||||
decortUrl: https://delta.qa.loc
|
||||
domain: dynamix
|
||||
token":
|
||||
access_token: string_token
|
||||
token_type: bearer
|
||||
refresh_token: string_refresh_token
|
||||
expiry: 2023-11-24T12:40:27.954150524+03:00
|
||||
retries: 5
|
||||
sslSkipVerify: true
|
||||
timeout: 5m
|
||||
path_cfg: config
|
||||
path_token: token
|
||||
timeToRefresh: 5
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
appId: <APP_ID>
|
||||
appSecret: <APP_SECRET>
|
||||
ssoUrl: https://sso.digitalenergy.online
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": true
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: true
|
||||
Reference in New Issue
Block a user