This commit is contained in:
2026-06-19 17:34:28 +03:00
parent cd5d1c9d0b
commit b897b3447a
1513 changed files with 1 additions and 107093 deletions

View File

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

View File

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

View File

@@ -1,7 +0,0 @@
package client
import "time"
type Config struct {
QueryTimeout time.Duration
}