update go.mod and imports
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
package computeci
|
||||
|
||||
import (
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to computeci
|
||||
|
||||
95
pkg/cloudapi/computeci/filter_test.go
Normal file
95
pkg/cloudapi/computeci/filter_test.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package computeci
|
||||
|
||||
import "testing"
|
||||
|
||||
var computeciItems = ListComputeCI{
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Name: "computeci_1",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Name: "computeci_2",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"SVA_KVM_X86",
|
||||
},
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Name: "computeci_3",
|
||||
Status: "DISABLED",
|
||||
Template: "",
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := computeciItems.FilterByID(2).FindOne()
|
||||
|
||||
if actual.ID != 2 {
|
||||
t.Fatal("expected ID 2, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := computeciItems.FilterByName("computeci_3").FindOne()
|
||||
|
||||
if actual.Name != "computeci_3" {
|
||||
t.Fatal("expected Name 'computeci_2', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := computeciItems.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := computeciItems.FilterFunc(func(icc ItemComputeCI) bool {
|
||||
for _, item := range icc.Drivers {
|
||||
if item == "KVM_X86" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, driver := range item.Drivers {
|
||||
if driver != "KVM_X86" {
|
||||
t.Fatal("expected 'KVM_X86' Driver, found: ", driver)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,30 +3,25 @@ package computeci
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for information about computeci
|
||||
type GetRequest struct {
|
||||
// ID of the Compute CI
|
||||
// Required: true
|
||||
ComputeCIID uint64 `url:"computeciId" json:"computeciId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) validate() error {
|
||||
if krq.ComputeCIID == 0 {
|
||||
return errors.New("field ComputeCIID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets information about computeci by ID
|
||||
func (c ComputeCI) Get(ctx context.Context, req GetRequest) (*ItemComputeCI, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validatonError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validatonError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/computeci/get"
|
||||
|
||||
@@ -3,7 +3,7 @@ package computeci
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
|
||||
Reference in New Issue
Block a user