v1.5.0-gamma
This commit is contained in:
@@ -3,7 +3,7 @@ package k8ci
|
||||
// FilterByID returns ListK8CI with specified ID.
|
||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.ID == id
|
||||
return ikc.ID == id
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
@@ -12,7 +12,7 @@ func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||
// FilterByName returns ListK8CI with specified Name.
|
||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||
predicate := func(ikc ItemK8CI) bool {
|
||||
return ikc.RecordK8CI.Name == name
|
||||
return ikc.Name == name
|
||||
}
|
||||
|
||||
return lkc.FilterFunc(predicate)
|
||||
@@ -22,21 +22,23 @@ func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||
func (lkc ListK8CI) FilterFunc(predicate func(ItemK8CI) bool) ListK8CI {
|
||||
var result ListK8CI
|
||||
|
||||
for _, item := range lkc {
|
||||
for _, item := range lkc.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 ItemK8CI
|
||||
// If none was found, returns an empty struct.
|
||||
func (lkc ListK8CI) FindOne() ItemK8CI {
|
||||
if len(lkc) == 0 {
|
||||
if len(lkc.Data) == 0 {
|
||||
return ItemK8CI{}
|
||||
}
|
||||
|
||||
return lkc[0]
|
||||
return lkc.Data[0]
|
||||
}
|
||||
|
||||
@@ -3,33 +3,50 @@ package k8ci
|
||||
import "testing"
|
||||
|
||||
var k8ciItems = ListK8CI{
|
||||
ItemK8CI{
|
||||
CreatedTime: 123902139,
|
||||
RecordK8CI: RecordK8CI{
|
||||
Data: []ItemK8CI{
|
||||
{
|
||||
CreatedTime: 123902139,
|
||||
Status: "ENABLED",
|
||||
Description: "",
|
||||
ID: 1,
|
||||
Name: "purple_snake",
|
||||
Version: "1",
|
||||
LBImageID: 654,
|
||||
NetworkPlugins: []string{
|
||||
"flannel",
|
||||
"calico",
|
||||
"weavenet",
|
||||
},
|
||||
},
|
||||
},
|
||||
ItemK8CI{
|
||||
CreatedTime: 123902232,
|
||||
RecordK8CI: RecordK8CI{
|
||||
{
|
||||
CreatedTime: 123902232,
|
||||
Status: "ENABLED",
|
||||
Description: "",
|
||||
ID: 2,
|
||||
Name: "green_giant",
|
||||
Version: "2",
|
||||
LBImageID: 654,
|
||||
NetworkPlugins: []string{
|
||||
"flannel",
|
||||
"calico",
|
||||
"weavenet",
|
||||
},
|
||||
},
|
||||
},
|
||||
ItemK8CI{
|
||||
CreatedTime: 123902335,
|
||||
RecordK8CI: RecordK8CI{
|
||||
{
|
||||
CreatedTime: 123902335,
|
||||
Status: "DISABLED",
|
||||
Description: "",
|
||||
ID: 3,
|
||||
Name: "magenta_cloud",
|
||||
Version: "3",
|
||||
NetworkPlugins: []string{
|
||||
"flannel",
|
||||
"calico",
|
||||
"weavenet",
|
||||
},
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
@@ -53,11 +70,11 @@ func TestFilterFunc(t *testing.T) {
|
||||
return ikc.CreatedTime > 123902139
|
||||
})
|
||||
|
||||
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.CreatedTime < 123902139 {
|
||||
t.Fatal("expected CreatedTime greater than 123902139, found: ", item.CreatedTime)
|
||||
}
|
||||
@@ -67,7 +84,7 @@ func TestFilterFunc(t *testing.T) {
|
||||
func TestSortingByCreatedTime(t *testing.T) {
|
||||
actual := k8ciItems.SortByCreatedTime(true)
|
||||
|
||||
if actual[0].CreatedTime != 123902335 && actual[2].CreatedTime != 123902139 {
|
||||
if actual.Data[0].CreatedTime != 123902335 && actual.Data[2].CreatedTime != 123902139 {
|
||||
t.Fatal("expected inverse sort, found normal")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,30 @@ import (
|
||||
|
||||
// Request struct for get list information about images
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"id,omitempty" json:"id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by worker driver
|
||||
// Required: false
|
||||
WorkerDriver string `url:"workerDriver,omitempty" json:"workerDriver,omitempty"`
|
||||
|
||||
// Find by master driver
|
||||
// Required: false
|
||||
MasterDriver string `url:"masterDriver,omitempty" json:"masterDriver,omitempty"`
|
||||
|
||||
// Find by network plugin
|
||||
// Required: false
|
||||
NetworkPlugins string `url:"netPlugins,omitempty" json:"netPlugins,omitempty"`
|
||||
|
||||
// List disabled items as well
|
||||
// Required: false
|
||||
IncludeDisabled bool `url:"includeDisabled,omitempty" json:"includeDisabled,omitempty"`
|
||||
@@ -22,7 +46,7 @@ type ListRequest struct {
|
||||
}
|
||||
|
||||
// List gets list all k8ci catalog items available to the current user
|
||||
func (k K8CI) List(ctx context.Context, req ListRequest) (ListK8CI, error) {
|
||||
func (k K8CI) List(ctx context.Context, req ListRequest) (*ListK8CI, error) {
|
||||
url := "/cloudapi/k8ci/list"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -37,5 +61,5 @@ func (k K8CI) List(ctx context.Context, req ListRequest) (ListK8CI, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type ListDeletedRequest struct {
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted k8ci catalog items available to the current user
|
||||
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8CI, error) {
|
||||
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8CI, error) {
|
||||
url := "/cloudapi/k8ci/listDeleted"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -33,5 +33,5 @@ func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8CI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -5,12 +5,34 @@ type ItemK8CI struct {
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Main information about K8CI
|
||||
RecordK8CI
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// LB image ID
|
||||
LBImageID uint64 `json:"lbImageId"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network plugins
|
||||
NetworkPlugins []string `json:"networkPlugins"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Version
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// List of K8CI
|
||||
type ListK8CI []ItemK8CI
|
||||
type ListK8CI struct {
|
||||
Data []ItemK8CI `json:"data"`
|
||||
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about K8CI
|
||||
type RecordK8CI struct {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (lkc ListK8CI) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(lkc) == 0 {
|
||||
if len(lkc.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@ import "sort"
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lkc ListK8CI) SortByCreatedTime(inverse bool) ListK8CI {
|
||||
if len(lkc) < 2 {
|
||||
if len(lkc.Data) < 2 {
|
||||
return lkc
|
||||
}
|
||||
|
||||
sort.Slice(lkc, func(i, j int) bool {
|
||||
sort.Slice(lkc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lkc[i].CreatedTime > lkc[j].CreatedTime
|
||||
return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lkc[i].CreatedTime < lkc[j].CreatedTime
|
||||
return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lkc
|
||||
|
||||
Reference in New Issue
Block a user