v1.5.0-gamma
This commit is contained in:
@@ -31,21 +31,23 @@ func (lci ListComputeCI) FilterByStatus(status string) ListComputeCI {
|
||||
func (lci ListComputeCI) FilterFunc(predicate func(ItemComputeCI) bool) ListComputeCI {
|
||||
var result ListComputeCI
|
||||
|
||||
for _, item := range lci {
|
||||
for _, item := range lci.Data {
|
||||
if predicate(item) {
|
||||
result = append(result, item)
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemComputeCI
|
||||
// If none was found, returns an empty struct.
|
||||
func (lci ListComputeCI) FindOne() ItemComputeCI {
|
||||
if len(lci) == 0 {
|
||||
if lci.EntryCount == 0 {
|
||||
return ItemComputeCI{}
|
||||
}
|
||||
|
||||
return lci[0]
|
||||
return lci.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,42 +3,45 @@ package computeci
|
||||
import "testing"
|
||||
|
||||
var computeciItems = ListComputeCI{
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
Data: []ItemComputeCI{
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Name: "computeci_1",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Name: "computeci_1",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Name: "computeci_2",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Name: "computeci_2",
|
||||
Status: "ENABLED",
|
||||
Template: "",
|
||||
},
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"SVA_KVM_X86",
|
||||
{
|
||||
CustomFields: map[string]interface{}{},
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"SVA_KVM_X86",
|
||||
},
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Name: "computeci_3",
|
||||
Status: "DISABLED",
|
||||
Template: "",
|
||||
},
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Name: "computeci_3",
|
||||
Status: "DISABLED",
|
||||
Template: "",
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -60,11 +63,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := computeciItems.FilterByStatus("ENABLED")
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
|
||||
}
|
||||
@@ -81,11 +84,11 @@ func TestFilterFunc(t *testing.T) {
|
||||
return false
|
||||
})
|
||||
|
||||
if len(actual) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
for _, driver := range item.Drivers {
|
||||
if driver != "KVM_X86" {
|
||||
t.Fatal("expected 'KVM_X86' Driver, found: ", driver)
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
|
||||
// Request struct for get list of computeci
|
||||
type ListRequest struct {
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by computeci ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by drivers
|
||||
// Find by computeci ID
|
||||
Drivers []string `url:"drivers,omitempty" json:"drivers,omitempty"`
|
||||
|
||||
// If true list deleted instances as well
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includeDeleted,omitempty" json:"includeDeleted,omitempty"`
|
||||
@@ -22,7 +34,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list of computeci instances
|
||||
func (c ComputeCI) List(ctx context.Context, req ListRequest) (ListComputeCI, error) {
|
||||
func (c ComputeCI) List(ctx context.Context, req ListRequest) (*ListComputeCI, error) {
|
||||
url := "/cloudapi/computeci/list"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +49,5 @@ func (c ComputeCI) List(ctx context.Context, req ListRequest) (ListComputeCI, er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -28,4 +28,8 @@ type ItemComputeCI struct {
|
||||
}
|
||||
|
||||
// List of computeci instances
|
||||
type ListComputeCI []ItemComputeCI
|
||||
type ListComputeCI struct {
|
||||
Data []ItemComputeCI `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lci ListComputeCI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lci) == 0 {
|
||||
if lci.EntryCount == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user