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
7a06299f
Commit
7a06299f
authored
May 08, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apitesting: external serialization roundtrip test
parent
110f410e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
9 deletions
+40
-9
roundtrip.go
staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip.go
+40
-9
No files found.
staging/src/k8s.io/apimachinery/pkg/api/testing/roundtrip.go
View file @
7a06299f
...
...
@@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
runtimeserializer
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets"
)
...
...
@@ -125,24 +126,28 @@ func roundTripTypes(t *testing.T, scheme *runtime.Scheme, codecFactory runtimese
}
}
func
RoundTripSpecificKindWithoutProtobuf
(
t
*
testing
.
T
,
internalGVK
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
)
{
roundTripSpecificKind
(
t
,
internalGVK
,
scheme
,
codecFactory
,
fuzzer
,
nonRoundTrippableTypes
,
true
)
func
RoundTripSpecificKindWithoutProtobuf
(
t
*
testing
.
T
,
gvk
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
)
{
roundTripSpecificKind
(
t
,
gvk
,
scheme
,
codecFactory
,
fuzzer
,
nonRoundTrippableTypes
,
true
)
}
func
RoundTripSpecificKind
(
t
*
testing
.
T
,
internalGVK
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
)
{
roundTripSpecificKind
(
t
,
internalGVK
,
scheme
,
codecFactory
,
fuzzer
,
nonRoundTrippableTypes
,
false
)
func
RoundTripSpecificKind
(
t
*
testing
.
T
,
gvk
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
)
{
roundTripSpecificKind
(
t
,
gvk
,
scheme
,
codecFactory
,
fuzzer
,
nonRoundTrippableTypes
,
false
)
}
func
roundTripSpecificKind
(
t
*
testing
.
T
,
internalGVK
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
,
skipProtobuf
bool
)
{
if
nonRoundTrippableTypes
[
internalGVK
]
{
t
.
Logf
(
"skipping %v"
,
internalGVK
)
func
roundTripSpecificKind
(
t
*
testing
.
T
,
gvk
schema
.
GroupVersionKind
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
nonRoundTrippableTypes
map
[
schema
.
GroupVersionKind
]
bool
,
skipProtobuf
bool
)
{
if
nonRoundTrippableTypes
[
gvk
]
{
t
.
Logf
(
"skipping %v"
,
gvk
)
return
}
t
.
Logf
(
"round tripping %v"
,
internalGVK
)
t
.
Logf
(
"round tripping %v"
,
gvk
)
// Try a few times, since runTest uses random values.
for
i
:=
0
;
i
<
*
FuzzIters
;
i
++
{
roundTripToAllExternalVersions
(
t
,
scheme
,
codecFactory
,
fuzzer
,
internalGVK
,
nonRoundTrippableTypes
,
skipProtobuf
)
if
gvk
.
Version
==
runtime
.
APIVersionInternal
{
roundTripToAllExternalVersions
(
t
,
scheme
,
codecFactory
,
fuzzer
,
gvk
,
nonRoundTrippableTypes
,
skipProtobuf
)
}
else
{
roundTripOfExternalType
(
t
,
scheme
,
codecFactory
,
fuzzer
,
gvk
,
skipProtobuf
)
}
if
t
.
Failed
()
{
break
}
...
...
@@ -209,6 +214,32 @@ func roundTripToAllExternalVersions(t *testing.T, scheme *runtime.Scheme, codecF
}
}
func
roundTripOfExternalType
(
t
*
testing
.
T
,
scheme
*
runtime
.
Scheme
,
codecFactory
runtimeserializer
.
CodecFactory
,
fuzzer
*
fuzz
.
Fuzzer
,
externalGVK
schema
.
GroupVersionKind
,
skipProtobuf
bool
)
{
object
,
err
:=
scheme
.
New
(
externalGVK
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't make a %v? %v"
,
externalGVK
,
err
)
}
typeAcc
,
err
:=
meta
.
TypeAccessor
(
object
)
if
err
!=
nil
{
t
.
Fatalf
(
"%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableInternalTypes: %v"
,
externalGVK
,
err
)
}
fuzzInternalObject
(
t
,
fuzzer
,
object
)
externalGoType
:=
reflect
.
TypeOf
(
object
)
.
PkgPath
()
t
.
Logf
(
"
\t
round tripping external type %v %v"
,
externalGVK
,
externalGoType
)
typeAcc
.
SetKind
(
externalGVK
.
Kind
)
typeAcc
.
SetAPIVersion
(
externalGVK
.
GroupVersion
()
.
String
())
roundTrip
(
t
,
scheme
,
json
.
NewSerializer
(
json
.
DefaultMetaFactory
,
scheme
,
scheme
,
false
),
object
)
// TODO remove this hack after we're past the intermediate steps
if
!
skipProtobuf
{
roundTrip
(
t
,
scheme
,
protobuf
.
NewSerializer
(
scheme
,
scheme
,
"application/protobuf"
),
object
)
}
}
// roundTrip applies a single round-trip test to the given runtime object
// using the given codec. The round-trip test ensures that an object can be
// deep-copied and converted from internal -> versioned -> internal without
...
...
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