v1.5.0-delta
This commit is contained in:
@@ -49,21 +49,23 @@ func (lsep ListSEP) FilterByType(sepType string) ListSEP {
|
||||
func (lsep ListSEP) FilterFunc(predicate func(RecordSEP) bool) ListSEP {
|
||||
var result ListSEP
|
||||
|
||||
for _, item := range lsep {
|
||||
for _, item := range lsep.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 RecordSEP
|
||||
// If none was found, returns an empty struct.
|
||||
func (lsep ListSEP) FindOne() RecordSEP {
|
||||
if len(lsep) == 0 {
|
||||
if len(lsep.Data) == 0 {
|
||||
return RecordSEP{}
|
||||
}
|
||||
|
||||
return lsep[0]
|
||||
return lsep.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,110 +3,113 @@ package sep
|
||||
import "testing"
|
||||
|
||||
var seps = ListSEP{
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.61",
|
||||
"10.212.3.62",
|
||||
"10.212.3.63",
|
||||
Data: []RecordSEP{
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
27,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Milestones: 278329,
|
||||
Name: "sep_1",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
24,
|
||||
35,
|
||||
29,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.64",
|
||||
"10.212.3.65",
|
||||
"10.212.3.66",
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.61",
|
||||
"10.212.3.62",
|
||||
"10.212.3.63",
|
||||
},
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
32,
|
||||
26,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Milestones: 278337,
|
||||
Name: "sep_2",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
36,
|
||||
42,
|
||||
35,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.67",
|
||||
"10.212.3.68",
|
||||
"10.212.3.69",
|
||||
ConsumedBy: []uint64{
|
||||
27,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 1,
|
||||
ID: 1,
|
||||
Milestones: 278329,
|
||||
Name: "sep_1",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
24,
|
||||
35,
|
||||
29,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
38,
|
||||
28,
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.64",
|
||||
"10.212.3.65",
|
||||
"10.212.3.66",
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
32,
|
||||
26,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 2,
|
||||
ID: 2,
|
||||
Milestones: 278337,
|
||||
Name: "sep_2",
|
||||
ObjStatus: "CREATED",
|
||||
ProvidedBy: []uint64{
|
||||
36,
|
||||
42,
|
||||
35,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "ENABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Milestones: 278345,
|
||||
Name: "sep_3",
|
||||
ObjStatus: "DESTROYED",
|
||||
ProvidedBy: []uint64{
|
||||
49,
|
||||
48,
|
||||
41,
|
||||
{
|
||||
CKey: "",
|
||||
Meta: []interface{}{
|
||||
"osismodel",
|
||||
"cloudbroker",
|
||||
"sep",
|
||||
1,
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"API_IPs": []string{
|
||||
"10.212.3.67",
|
||||
"10.212.3.68",
|
||||
"10.212.3.69",
|
||||
},
|
||||
},
|
||||
ConsumedBy: []uint64{
|
||||
38,
|
||||
28,
|
||||
},
|
||||
Description: "",
|
||||
GID: 212,
|
||||
GUID: 3,
|
||||
ID: 3,
|
||||
Milestones: 278345,
|
||||
Name: "sep_3",
|
||||
ObjStatus: "DESTROYED",
|
||||
ProvidedBy: []uint64{
|
||||
49,
|
||||
48,
|
||||
41,
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "DISABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
SharedWith: []uint64{},
|
||||
TechStatus: "DISABLED",
|
||||
Type: "DES",
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -128,11 +131,11 @@ func TestFilterByName(t *testing.T) {
|
||||
func TestFilterByObjStatus(t *testing.T) {
|
||||
actual := seps.FilterByObjStatus("CREATED")
|
||||
|
||||
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.ObjStatus != "CREATED" {
|
||||
t.Fatal("expected ObjStatus 'CREATED', found: ", item.ObjStatus)
|
||||
}
|
||||
@@ -142,11 +145,11 @@ func TestFilterByObjStatus(t *testing.T) {
|
||||
func TestFilterByTechStatus(t *testing.T) {
|
||||
actual := seps.FilterByTechStatus("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.TechStatus != "ENABLED" {
|
||||
t.Fatal("expected TechStatus 'ENABLED', found: ", item.TechStatus)
|
||||
}
|
||||
@@ -156,11 +159,11 @@ func TestFilterByTechStatus(t *testing.T) {
|
||||
func TestFilterByType(t *testing.T) {
|
||||
actual := seps.FilterByType("DES")
|
||||
|
||||
if len(actual) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual))
|
||||
if len(actual.Data) != 3 {
|
||||
t.Fatal("expected 3 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual {
|
||||
for _, item := range actual.Data {
|
||||
if item.Type != "DES" {
|
||||
t.Fatal("expected Type 'DES', found: ", item.Type)
|
||||
}
|
||||
@@ -172,11 +175,11 @@ func TestFilterFunc(t *testing.T) {
|
||||
return len(rs.ConsumedBy) > 1
|
||||
})
|
||||
|
||||
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 len(item.ConsumedBy) <= 1 {
|
||||
t.Fatal("expected ConsumedBy to contain more than 1 element, found: ", len(item.ConsumedBy))
|
||||
}
|
||||
|
||||
@@ -8,6 +8,34 @@ import (
|
||||
|
||||
// Request struct for get list of SEPs
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by gId
|
||||
// Required: false
|
||||
GID uint64 `url:"gId,omitempty" json:"gId,omitempty"`
|
||||
|
||||
// Find by sep type
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||
|
||||
// Find by provided physical node id
|
||||
// Required: false
|
||||
ProvidedBy uint64 `url:"providedBy,omitempty" json:"providedBy,omitempty"`
|
||||
|
||||
// Find by techStatus
|
||||
// Required: false
|
||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
||||
|
||||
// Find by consumed physical node id
|
||||
// Required: false
|
||||
ConsumedBy uint64 `url:"consumedBy,omitempty" json:"consumedBy,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
@@ -18,7 +46,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list of SEPs
|
||||
func (s SEP) List(ctx context.Context, req ListRequest) (ListSEP, error) {
|
||||
func (s SEP) List(ctx context.Context, req ListRequest) (*ListSEP, error) {
|
||||
url := "/cloudbroker/sep/list"
|
||||
|
||||
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +61,5 @@ func (s SEP) List(ctx context.Context, req ListRequest) (ListSEP, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -124,4 +124,10 @@ type RecordSEP struct {
|
||||
}
|
||||
|
||||
// List SEPs
|
||||
type ListSEP []RecordSEP
|
||||
type ListSEP struct {
|
||||
// Data
|
||||
Data []RecordSEP `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lsep ListSEP) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lsep) == 0 {
|
||||
if len(lsep.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user