Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
dc3b3279
Commit
dc3b3279
authored
Feb 14, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow runtime.SetList() on an api.List
SetList doesn't allow api.List
parent
64678b71
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
helper.go
pkg/runtime/helper.go
+7
-0
helper_test.go
pkg/runtime/helper_test.go
+22
-0
No files found.
pkg/runtime/helper.go
View file @
dc3b3279
...
...
@@ -83,6 +83,9 @@ func ExtractList(obj Object) ([]Object, error) {
return
list
,
nil
}
// objectSliceType is the type of a slice of Objects
var
objectSliceType
=
reflect
.
TypeOf
([]
Object
{})
// SetList sets the given list object's Items member have the elements given in
// objects.
// Returns an error if list is not a List type (does not have an Items member),
...
...
@@ -96,6 +99,10 @@ func SetList(list Object, objects []Object) error {
if
err
!=
nil
{
return
err
}
if
items
.
Type
()
==
objectSliceType
{
items
.
Set
(
reflect
.
ValueOf
(
objects
))
return
nil
}
slice
:=
reflect
.
MakeSlice
(
items
.
Type
(),
len
(
objects
),
len
(
objects
))
for
i
:=
range
objects
{
dest
:=
slice
.
Index
(
i
)
...
...
pkg/runtime/helper_test.go
View file @
dc3b3279
...
...
@@ -22,6 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/google/gofuzz"
)
...
...
@@ -152,6 +153,27 @@ func TestSetList(t *testing.T) {
}
}
func
TestSetListToRuntimeObjectArray
(
t
*
testing
.
T
)
{
pl
:=
&
api
.
List
{}
list
:=
[]
runtime
.
Object
{
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"1"
}},
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"2"
}},
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"3"
}},
}
err
:=
runtime
.
SetList
(
pl
,
list
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
if
e
,
a
:=
len
(
list
),
len
(
pl
.
Items
);
e
!=
a
{
t
.
Fatalf
(
"Expected %v, got %v"
,
e
,
a
)
}
for
i
:=
range
list
{
if
e
,
a
:=
list
[
i
],
pl
.
Items
[
i
];
e
!=
a
{
t
.
Fatalf
(
"%d: unmatched: %s"
,
i
,
util
.
ObjectDiff
(
e
,
a
))
}
}
}
func
TestSetExtractListRoundTrip
(
t
*
testing
.
T
)
{
fuzzer
:=
fuzz
.
New
()
.
NilChance
(
0
)
.
NumElements
(
1
,
5
)
for
i
:=
0
;
i
<
5
;
i
++
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment