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
205cd90d
Commit
205cd90d
authored
Jul 06, 2017
by
Dr. Stefan Schimanski
Committed by
Dr. Stefan Schimanski
Jul 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apimachinery+apiserver: extract test types to work w/ deepcopy-gen
parent
954c356d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
567 additions
and
148 deletions
+567
-148
doc.go
...extensions-apiserver/examples/client-go/apis/cr/v1/doc.go
+18
-0
conversion_test.go
...ng/src/k8s.io/apimachinery/pkg/runtime/conversion_test.go
+13
-33
embedded_test.go
staging/src/k8s.io/apimachinery/pkg/runtime/embedded_test.go
+28
-60
scheme_test.go
staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go
+0
-0
codec_test.go
.../k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go
+0
-0
doc.go
...k8s.io/apimachinery/pkg/runtime/serializer/testing/doc.go
+19
-0
types.go
...s.io/apimachinery/pkg/runtime/serializer/testing/types.go
+109
-0
doc.go
staging/src/k8s.io/apimachinery/pkg/runtime/testing/doc.go
+19
-0
types.go
staging/src/k8s.io/apimachinery/pkg/runtime/testing/types.go
+212
-0
apiserver_test.go
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
+11
-31
openapi_test.go
...rc/k8s.io/apiserver/pkg/endpoints/openapi/openapi_test.go
+6
-24
types.go
...c/k8s.io/apiserver/pkg/endpoints/openapi/testing/types.go
+40
-0
zz_generated.deepcopy.go
...er/pkg/endpoints/openapi/testing/zz_generated.deepcopy.go
+43
-0
doc.go
staging/src/k8s.io/apiserver/pkg/endpoints/testing/doc.go
+19
-0
types.go
staging/src/k8s.io/apiserver/pkg/endpoints/testing/types.go
+11
-0
doc.go
staging/src/k8s.io/apiserver/pkg/storage/testing/doc.go
+19
-0
No files found.
staging/src/k8s.io/apiextensions-apiserver/examples/client-go/apis/cr/v1/doc.go
0 → 100644
View file @
205cd90d
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +k8s:deepcopy-gen=package
package
v1
staging/src/k8s.io/apimachinery/pkg/runtime/conversion_test.go
View file @
205cd90d
...
@@ -22,37 +22,17 @@ import (
...
@@ -22,37 +22,17 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
runtimetesting
"k8s.io/apimachinery/pkg/runtime/testing"
)
)
type
InternalComplex
struct
{
runtime
.
TypeMeta
String
string
Integer
int
Integer64
int64
Int64
int64
Bool
bool
}
type
ExternalComplex
struct
{
runtime
.
TypeMeta
`json:",inline"`
String
string
`json:"string" description:"testing"`
Integer
int
`json:"int"`
Integer64
int64
`json:",omitempty"`
Int64
int64
Bool
bool
`json:"bool"`
}
func
(
obj
*
InternalComplex
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExternalComplex
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
TestStringMapConversion
(
t
*
testing
.
T
)
{
func
TestStringMapConversion
(
t
*
testing
.
T
)
{
internalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
runtime
.
APIVersionInternal
}
internalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
runtime
.
APIVersionInternal
}
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"external"
}
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"external"
}
scheme
:=
runtime
.
NewScheme
()
scheme
:=
runtime
.
NewScheme
()
scheme
.
Log
(
t
)
scheme
.
Log
(
t
)
scheme
.
AddKnownTypeWithName
(
internalGV
.
WithKind
(
"Complex"
),
&
InternalComplex
{})
scheme
.
AddKnownTypeWithName
(
internalGV
.
WithKind
(
"Complex"
),
&
runtimetesting
.
InternalComplex
{})
scheme
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"Complex"
),
&
ExternalComplex
{})
scheme
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"Complex"
),
&
runtimetesting
.
ExternalComplex
{})
testCases
:=
map
[
string
]
struct
{
testCases
:=
map
[
string
]
struct
{
input
map
[
string
][]
string
input
map
[
string
][]
string
...
@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) {
...
@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) {
"int"
:
{
"1"
},
"int"
:
{
"1"
},
"Integer64"
:
{
"2"
},
"Integer64"
:
{
"2"
},
},
},
expected
:
&
ExternalComplex
{
String
:
"value"
,
Integer
:
1
},
expected
:
&
runtimetesting
.
ExternalComplex
{
String
:
"value"
,
Integer
:
1
},
},
},
"returns error on bad int"
:
{
"returns error on bad int"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"int"
:
{
"a"
},
"int"
:
{
"a"
},
},
},
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
expected
:
&
ExternalComplex
{},
expected
:
&
runtimetesting
.
ExternalComplex
{},
},
},
"parses int64"
:
{
"parses int64"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"Int64"
:
{
"-1"
},
"Int64"
:
{
"-1"
},
},
},
expected
:
&
ExternalComplex
{
Int64
:
-
1
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Int64
:
-
1
},
},
},
"returns error on bad int64"
:
{
"returns error on bad int64"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"Int64"
:
{
"a"
},
"Int64"
:
{
"a"
},
},
},
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
expected
:
&
ExternalComplex
{},
expected
:
&
runtimetesting
.
ExternalComplex
{},
},
},
"parses boolean true"
:
{
"parses boolean true"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"true"
},
"bool"
:
{
"true"
},
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Bool
:
true
},
},
},
"parses boolean any value"
:
{
"parses boolean any value"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"foo"
},
"bool"
:
{
"foo"
},
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Bool
:
true
},
},
},
"parses boolean false"
:
{
"parses boolean false"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"false"
},
"bool"
:
{
"false"
},
},
},
expected
:
&
ExternalComplex
{
Bool
:
false
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Bool
:
false
},
},
},
"parses boolean empty value"
:
{
"parses boolean empty value"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"bool"
:
{
""
},
"bool"
:
{
""
},
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Bool
:
true
},
},
},
"parses boolean no value"
:
{
"parses boolean no value"
:
{
input
:
map
[
string
][]
string
{
input
:
map
[
string
][]
string
{
"bool"
:
{},
"bool"
:
{},
},
},
expected
:
&
ExternalComplex
{
Bool
:
false
},
expected
:
&
runtimetesting
.
ExternalComplex
{
Bool
:
false
},
},
},
}
}
for
k
,
tc
:=
range
testCases
{
for
k
,
tc
:=
range
testCases
{
out
:=
&
ExternalComplex
{}
out
:=
&
runtimetesting
.
ExternalComplex
{}
if
err
:=
scheme
.
Convert
(
&
tc
.
input
,
out
,
nil
);
(
tc
.
errFn
==
nil
&&
err
!=
nil
)
||
(
tc
.
errFn
!=
nil
&&
!
tc
.
errFn
(
err
))
{
if
err
:=
scheme
.
Convert
(
&
tc
.
input
,
out
,
nil
);
(
tc
.
errFn
==
nil
&&
err
!=
nil
)
||
(
tc
.
errFn
!=
nil
&&
!
tc
.
errFn
(
err
))
{
t
.
Errorf
(
"%s: unexpected error: %v"
,
k
,
err
)
t
.
Errorf
(
"%s: unexpected error: %v"
,
k
,
err
)
continue
continue
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/embedded_test.go
View file @
205cd90d
...
@@ -25,50 +25,18 @@ import (
...
@@ -25,50 +25,18 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/runtime/serializer"
runtimetesting
"k8s.io/apimachinery/pkg/runtime/testing"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/diff"
)
)
type
EmbeddedTest
struct
{
runtime
.
TypeMeta
ID
string
Object
runtime
.
Object
EmptyObject
runtime
.
Object
}
type
EmbeddedTestExternal
struct
{
runtime
.
TypeMeta
`json:",inline"`
ID
string
`json:"id,omitempty"`
Object
runtime
.
RawExtension
`json:"object,omitempty"`
EmptyObject
runtime
.
RawExtension
`json:"emptyObject,omitempty"`
}
type
ObjectTest
struct
{
runtime
.
TypeMeta
ID
string
Items
[]
runtime
.
Object
}
type
ObjectTestExternal
struct
{
runtime
.
TypeMeta
`yaml:",inline" json:",inline"`
ID
string
`json:"id,omitempty"`
Items
[]
runtime
.
RawExtension
`json:"items,omitempty"`
}
func
(
obj
*
ObjectTest
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ObjectTestExternal
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
EmbeddedTest
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
EmbeddedTestExternal
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
TestDecodeEmptyRawExtensionAsObject
(
t
*
testing
.
T
)
{
func
TestDecodeEmptyRawExtensionAsObject
(
t
*
testing
.
T
)
{
internalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
runtime
.
APIVersionInternal
}
internalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
runtime
.
APIVersionInternal
}
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"v1test"
}
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"v1test"
}
externalGVK
:=
externalGV
.
WithKind
(
"ObjectTest"
)
externalGVK
:=
externalGV
.
WithKind
(
"ObjectTest"
)
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypes
(
internalGV
,
&
ObjectTest
{})
s
.
AddKnownTypes
(
internalGV
,
&
runtimetesting
.
ObjectTest
{})
s
.
AddKnownTypeWithName
(
externalGVK
,
&
ObjectTestExternal
{})
s
.
AddKnownTypeWithName
(
externalGVK
,
&
runtimetesting
.
ObjectTestExternal
{})
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
...
@@ -76,7 +44,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
...
@@ -76,7 +44,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
test
:=
obj
.
(
*
ObjectTest
)
test
:=
obj
.
(
*
runtimetesting
.
ObjectTest
)
if
unk
,
ok
:=
test
.
Items
[
0
]
.
(
*
runtime
.
Unknown
);
!
ok
||
unk
.
Kind
!=
""
||
unk
.
APIVersion
!=
""
||
string
(
unk
.
Raw
)
!=
"{}"
||
unk
.
ContentType
!=
runtime
.
ContentTypeJSON
{
if
unk
,
ok
:=
test
.
Items
[
0
]
.
(
*
runtime
.
Unknown
);
!
ok
||
unk
.
Kind
!=
""
||
unk
.
APIVersion
!=
""
||
string
(
unk
.
Raw
)
!=
"{}"
||
unk
.
ContentType
!=
runtime
.
ContentTypeJSON
{
t
.
Fatalf
(
"unexpected object: %#v"
,
test
.
Items
[
0
])
t
.
Fatalf
(
"unexpected object: %#v"
,
test
.
Items
[
0
])
}
}
...
@@ -88,7 +56,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
...
@@ -88,7 +56,7 @@ func TestDecodeEmptyRawExtensionAsObject(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
test
=
obj
.
(
*
ObjectTest
)
test
=
obj
.
(
*
runtimetesting
.
ObjectTest
)
if
unk
,
ok
:=
test
.
Items
[
0
]
.
(
*
runtime
.
Unknown
);
!
ok
||
unk
.
Kind
!=
""
||
unk
.
APIVersion
!=
""
||
string
(
unk
.
Raw
)
!=
`{"kind":"Other","apiVersion":"v1"}`
||
unk
.
ContentType
!=
runtime
.
ContentTypeJSON
{
if
unk
,
ok
:=
test
.
Items
[
0
]
.
(
*
runtime
.
Unknown
);
!
ok
||
unk
.
Kind
!=
""
||
unk
.
APIVersion
!=
""
||
string
(
unk
.
Raw
)
!=
`{"kind":"Other","apiVersion":"v1"}`
||
unk
.
ContentType
!=
runtime
.
ContentTypeJSON
{
t
.
Fatalf
(
"unexpected object: %#v"
,
test
.
Items
[
0
])
t
.
Fatalf
(
"unexpected object: %#v"
,
test
.
Items
[
0
])
}
}
...
@@ -102,29 +70,29 @@ func TestArrayOfRuntimeObject(t *testing.T) {
...
@@ -102,29 +70,29 @@ func TestArrayOfRuntimeObject(t *testing.T) {
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"v1test"
}
externalGV
:=
schema
.
GroupVersion
{
Group
:
"test.group"
,
Version
:
"v1test"
}
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypes
(
internalGV
,
&
EmbeddedTest
{})
s
.
AddKnownTypes
(
internalGV
,
&
runtimetesting
.
EmbeddedTest
{})
s
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"EmbeddedTest"
),
&
EmbeddedTestExternal
{})
s
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"EmbeddedTest"
),
&
runtimetesting
.
EmbeddedTestExternal
{})
s
.
AddKnownTypes
(
internalGV
,
&
ObjectTest
{})
s
.
AddKnownTypes
(
internalGV
,
&
runtimetesting
.
ObjectTest
{})
s
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"ObjectTest"
),
&
ObjectTestExternal
{})
s
.
AddKnownTypeWithName
(
externalGV
.
WithKind
(
"ObjectTest"
),
&
runtimetesting
.
ObjectTestExternal
{})
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
innerItems
:=
[]
runtime
.
Object
{
innerItems
:=
[]
runtime
.
Object
{
&
EmbeddedTest
{
ID
:
"baz"
},
&
runtimetesting
.
EmbeddedTest
{
ID
:
"baz"
},
}
}
items
:=
[]
runtime
.
Object
{
items
:=
[]
runtime
.
Object
{
&
EmbeddedTest
{
ID
:
"foo"
},
&
runtimetesting
.
EmbeddedTest
{
ID
:
"foo"
},
&
EmbeddedTest
{
ID
:
"bar"
},
&
runtimetesting
.
EmbeddedTest
{
ID
:
"bar"
},
// TODO: until YAML is removed, this JSON must be in ascending key order to ensure consistent roundtrip serialization
// TODO: until YAML is removed, this JSON must be in ascending key order to ensure consistent roundtrip serialization
&
runtime
.
Unknown
{
&
runtime
.
Unknown
{
Raw
:
[]
byte
(
`{"apiVersion":"unknown.group/unknown","foo":"bar","kind":"OtherTest"}`
),
Raw
:
[]
byte
(
`{"apiVersion":"unknown.group/unknown","foo":"bar","kind":"OtherTest"}`
),
ContentType
:
runtime
.
ContentTypeJSON
,
ContentType
:
runtime
.
ContentTypeJSON
,
},
},
&
ObjectTest
{
&
runtimetesting
.
ObjectTest
{
Items
:
runtime
.
NewEncodableList
(
codec
,
innerItems
),
Items
:
runtime
.
NewEncodableList
(
codec
,
innerItems
),
},
},
}
}
internal
:=
&
ObjectTest
{
internal
:=
&
runtimetesting
.
ObjectTest
{
Items
:
runtime
.
NewEncodableList
(
codec
,
items
),
Items
:
runtime
.
NewEncodableList
(
codec
,
items
),
}
}
wire
,
err
:=
runtime
.
Encode
(
codec
,
internal
)
wire
,
err
:=
runtime
.
Encode
(
codec
,
internal
)
...
@@ -133,13 +101,13 @@ func TestArrayOfRuntimeObject(t *testing.T) {
...
@@ -133,13 +101,13 @@ func TestArrayOfRuntimeObject(t *testing.T) {
}
}
t
.
Logf
(
"Wire format is:
\n
%s
\n
"
,
string
(
wire
))
t
.
Logf
(
"Wire format is:
\n
%s
\n
"
,
string
(
wire
))
obj
:=
&
ObjectTestExternal
{}
obj
:=
&
runtimetesting
.
ObjectTestExternal
{}
if
err
:=
json
.
Unmarshal
(
wire
,
obj
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
wire
,
obj
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
t
.
Logf
(
"exact wire is: %s"
,
string
(
obj
.
Items
[
0
]
.
Raw
))
t
.
Logf
(
"exact wire is: %s"
,
string
(
obj
.
Items
[
0
]
.
Raw
))
items
[
3
]
=
&
ObjectTest
{
Items
:
innerItems
}
items
[
3
]
=
&
runtimetesting
.
ObjectTest
{
Items
:
innerItems
}
internal
.
Items
=
items
internal
.
Items
=
items
decoded
,
err
:=
runtime
.
Decode
(
codec
,
wire
)
decoded
,
err
:=
runtime
.
Decode
(
codec
,
wire
)
...
@@ -178,15 +146,15 @@ func TestNestedObject(t *testing.T) {
...
@@ -178,15 +146,15 @@ func TestNestedObject(t *testing.T) {
embeddedTestExternalGVK
:=
externalGV
.
WithKind
(
"EmbeddedTest"
)
embeddedTestExternalGVK
:=
externalGV
.
WithKind
(
"EmbeddedTest"
)
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypes
(
internalGV
,
&
EmbeddedTest
{})
s
.
AddKnownTypes
(
internalGV
,
&
runtimetesting
.
EmbeddedTest
{})
s
.
AddKnownTypeWithName
(
embeddedTestExternalGVK
,
&
EmbeddedTestExternal
{})
s
.
AddKnownTypeWithName
(
embeddedTestExternalGVK
,
&
runtimetesting
.
EmbeddedTestExternal
{})
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
codec
:=
serializer
.
NewCodecFactory
(
s
)
.
LegacyCodec
(
externalGV
)
inner
:=
&
EmbeddedTest
{
inner
:=
&
runtimetesting
.
EmbeddedTest
{
ID
:
"inner"
,
ID
:
"inner"
,
}
}
outer
:=
&
EmbeddedTest
{
outer
:=
&
runtimetesting
.
EmbeddedTest
{
ID
:
"outer"
,
ID
:
"outer"
,
Object
:
runtime
.
NewEncodable
(
codec
,
inner
),
Object
:
runtime
.
NewEncodable
(
codec
,
inner
),
}
}
...
@@ -210,18 +178,18 @@ func TestNestedObject(t *testing.T) {
...
@@ -210,18 +178,18 @@ func TestNestedObject(t *testing.T) {
t
.
Errorf
(
"Expected unequal %#v %#v"
,
e
,
a
)
t
.
Errorf
(
"Expected unequal %#v %#v"
,
e
,
a
)
}
}
obj
,
err
:=
runtime
.
Decode
(
codec
,
decoded
.
(
*
EmbeddedTest
)
.
Object
.
(
*
runtime
.
Unknown
)
.
Raw
)
obj
,
err
:=
runtime
.
Decode
(
codec
,
decoded
.
(
*
runtimetesting
.
EmbeddedTest
)
.
Object
.
(
*
runtime
.
Unknown
)
.
Raw
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
decoded
.
(
*
EmbeddedTest
)
.
Object
=
obj
decoded
.
(
*
runtimetesting
.
EmbeddedTest
)
.
Object
=
obj
if
e
,
a
:=
outer
,
decoded
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
outer
,
decoded
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected equal %#v %#v"
,
e
,
a
)
t
.
Errorf
(
"Expected equal %#v %#v"
,
e
,
a
)
}
}
// test JSON decoding of the external object, which should preserve
// test JSON decoding of the external object, which should preserve
// raw bytes
// raw bytes
var
externalViaJSON
EmbeddedTestExternal
var
externalViaJSON
runtimetesting
.
EmbeddedTestExternal
err
=
json
.
Unmarshal
(
wire
,
&
externalViaJSON
)
err
=
json
.
Unmarshal
(
wire
,
&
externalViaJSON
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected decode error %v"
,
err
)
t
.
Fatalf
(
"Unexpected decode error %v"
,
err
)
...
@@ -237,7 +205,7 @@ func TestNestedObject(t *testing.T) {
...
@@ -237,7 +205,7 @@ func TestNestedObject(t *testing.T) {
// Generic Unmarshalling of JSON cannot load the nested objects because there is
// Generic Unmarshalling of JSON cannot load the nested objects because there is
// no default schema set. Consumers wishing to get direct JSON decoding must use
// no default schema set. Consumers wishing to get direct JSON decoding must use
// the external representation
// the external representation
var
decodedViaJSON
EmbeddedTest
var
decodedViaJSON
runtimetesting
.
EmbeddedTest
err
=
json
.
Unmarshal
(
wire
,
&
decodedViaJSON
)
err
=
json
.
Unmarshal
(
wire
,
&
decodedViaJSON
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"Expeceted decode error"
)
t
.
Fatal
(
"Expeceted decode error"
)
...
@@ -257,12 +225,12 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) {
...
@@ -257,12 +225,12 @@ func TestDeepCopyOfRuntimeObject(t *testing.T) {
embeddedTestExternalGVK
:=
externalGV
.
WithKind
(
"EmbeddedTest"
)
embeddedTestExternalGVK
:=
externalGV
.
WithKind
(
"EmbeddedTest"
)
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypes
(
internalGV
,
&
EmbeddedTest
{})
s
.
AddKnownTypes
(
internalGV
,
&
runtimetesting
.
EmbeddedTest
{})
s
.
AddKnownTypeWithName
(
embeddedTestExternalGVK
,
&
EmbeddedTestExternal
{})
s
.
AddKnownTypeWithName
(
embeddedTestExternalGVK
,
&
runtimetesting
.
EmbeddedTestExternal
{})
original
:=
&
EmbeddedTest
{
original
:=
&
runtimetesting
.
EmbeddedTest
{
ID
:
"outer"
,
ID
:
"outer"
,
Object
:
&
EmbeddedTest
{
Object
:
&
runtimetesting
.
EmbeddedTest
{
ID
:
"inner"
,
ID
:
"inner"
,
},
},
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go
View file @
205cd90d
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go
View file @
205cd90d
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/testing/doc.go
0 → 100644
View file @
205cd90d
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +k8s:deepcopy-gen=package
package
testing
staging/src/k8s.io/apimachinery/pkg/runtime/serializer/testing/types.go
0 → 100644
View file @
205cd90d
/*
Copyright 2014 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
testing
import
(
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Test a weird version/kind embedding format.
// +k8s:deepcopy-gen=false
type
MyWeirdCustomEmbeddedVersionKindField
struct
{
ID
string
`json:"ID,omitempty"`
APIVersion
string
`json:"myVersionKey,omitempty"`
ObjectKind
string
`json:"myKindKey,omitempty"`
Z
string
`json:"Z,omitempty"`
Y
uint64
`json:"Y,omitempty"`
}
type
TestType1
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
C
int8
`json:"C,omitempty"`
D
int16
`json:"D,omitempty"`
E
int32
`json:"E,omitempty"`
F
int64
`json:"F,omitempty"`
G
uint
`json:"G,omitempty"`
H
uint8
`json:"H,omitempty"`
I
uint16
`json:"I,omitempty"`
J
uint32
`json:"J,omitempty"`
K
uint64
`json:"K,omitempty"`
L
bool
`json:"L,omitempty"`
M
map
[
string
]
int
`json:"M,omitempty"`
N
map
[
string
]
TestType2
`json:"N,omitempty"`
O
*
TestType2
`json:"O,omitempty"`
P
[]
TestType2
`json:"Q,omitempty"`
}
type
TestType2
struct
{
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
}
type
ExternalTestType2
struct
{
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
}
type
ExternalTestType1
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
C
int8
`json:"C,omitempty"`
D
int16
`json:"D,omitempty"`
E
int32
`json:"E,omitempty"`
F
int64
`json:"F,omitempty"`
G
uint
`json:"G,omitempty"`
H
uint8
`json:"H,omitempty"`
I
uint16
`json:"I,omitempty"`
J
uint32
`json:"J,omitempty"`
K
uint64
`json:"K,omitempty"`
L
bool
`json:"L,omitempty"`
M
map
[
string
]
int
`json:"M,omitempty"`
N
map
[
string
]
ExternalTestType2
`json:"N,omitempty"`
O
*
ExternalTestType2
`json:"O,omitempty"`
P
[]
ExternalTestType2
`json:"Q,omitempty"`
}
type
ExternalInternalSame
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
TestType2
`json:"A,omitempty"`
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
GetObjectKind
()
schema
.
ObjectKind
{
return
obj
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
SetGroupVersionKind
(
gvk
schema
.
GroupVersionKind
)
{
obj
.
APIVersion
,
obj
.
ObjectKind
=
gvk
.
ToAPIVersionAndKind
()
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
GroupVersionKind
()
schema
.
GroupVersionKind
{
return
schema
.
FromAPIVersionAndKind
(
obj
.
APIVersion
,
obj
.
ObjectKind
)
}
func
(
obj
*
ExternalInternalSame
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
MyWeirdCustomEmbeddedVersionKindField
}
func
(
obj
*
TestType1
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
MyWeirdCustomEmbeddedVersionKindField
}
func
(
obj
*
ExternalTestType1
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
MyWeirdCustomEmbeddedVersionKindField
}
func
(
obj
*
TestType2
)
GetObjectKind
()
schema
.
ObjectKind
{
return
schema
.
EmptyObjectKind
}
func
(
obj
*
ExternalTestType2
)
GetObjectKind
()
schema
.
ObjectKind
{
return
schema
.
EmptyObjectKind
}
staging/src/k8s.io/apimachinery/pkg/runtime/testing/doc.go
0 → 100644
View file @
205cd90d
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +k8s:deepcopy-gen=package
package
testing
staging/src/k8s.io/apimachinery/pkg/runtime/testing/types.go
0 → 100644
View file @
205cd90d
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
testing
import
(
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type
EmbeddedTest
struct
{
runtime
.
TypeMeta
ID
string
Object
runtime
.
Object
EmptyObject
runtime
.
Object
}
type
EmbeddedTestExternal
struct
{
runtime
.
TypeMeta
`json:",inline"`
ID
string
`json:"id,omitempty"`
Object
runtime
.
RawExtension
`json:"object,omitempty"`
EmptyObject
runtime
.
RawExtension
`json:"emptyObject,omitempty"`
}
type
ObjectTest
struct
{
runtime
.
TypeMeta
ID
string
Items
[]
runtime
.
Object
}
type
ObjectTestExternal
struct
{
runtime
.
TypeMeta
`yaml:",inline" json:",inline"`
ID
string
`json:"id,omitempty"`
Items
[]
runtime
.
RawExtension
`json:"items,omitempty"`
}
type
InternalSimple
struct
{
runtime
.
TypeMeta
`json:",inline"`
TestString
string
`json:"testString"`
}
type
ExternalSimple
struct
{
runtime
.
TypeMeta
`json:",inline"`
TestString
string
`json:"testString"`
}
type
ExtensionA
struct
{
runtime
.
TypeMeta
`json:",inline"`
TestString
string
`json:"testString"`
}
type
ExtensionB
struct
{
runtime
.
TypeMeta
`json:",inline"`
TestString
string
`json:"testString"`
}
type
ExternalExtensionType
struct
{
runtime
.
TypeMeta
`json:",inline"`
Extension
runtime
.
RawExtension
`json:"extension"`
}
type
InternalExtensionType
struct
{
runtime
.
TypeMeta
`json:",inline"`
Extension
runtime
.
Object
`json:"extension"`
}
type
ExternalOptionalExtensionType
struct
{
runtime
.
TypeMeta
`json:",inline"`
Extension
runtime
.
RawExtension
`json:"extension,omitempty"`
}
type
InternalOptionalExtensionType
struct
{
runtime
.
TypeMeta
`json:",inline"`
Extension
runtime
.
Object
`json:"extension,omitempty"`
}
type
InternalComplex
struct
{
runtime
.
TypeMeta
String
string
Integer
int
Integer64
int64
Int64
int64
Bool
bool
}
type
ExternalComplex
struct
{
runtime
.
TypeMeta
`json:",inline"`
String
string
`json:"string" description:"testing"`
Integer
int
`json:"int"`
Integer64
int64
`json:",omitempty"`
Int64
int64
Bool
bool
`json:"bool"`
}
// Test a weird version/kind embedding format.
// +k8s:deepcopy-gen=false
type
MyWeirdCustomEmbeddedVersionKindField
struct
{
ID
string
`json:"ID,omitempty"`
APIVersion
string
`json:"myVersionKey,omitempty"`
ObjectKind
string
`json:"myKindKey,omitempty"`
Z
string
`json:"Z,omitempty"`
Y
uint64
`json:"Y,omitempty"`
}
type
TestType1
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
C
int8
`json:"C,omitempty"`
D
int16
`json:"D,omitempty"`
E
int32
`json:"E,omitempty"`
F
int64
`json:"F,omitempty"`
G
uint
`json:"G,omitempty"`
H
uint8
`json:"H,omitempty"`
I
uint16
`json:"I,omitempty"`
J
uint32
`json:"J,omitempty"`
K
uint64
`json:"K,omitempty"`
L
bool
`json:"L,omitempty"`
M
map
[
string
]
int
`json:"M,omitempty"`
N
map
[
string
]
TestType2
`json:"N,omitempty"`
O
*
TestType2
`json:"O,omitempty"`
P
[]
TestType2
`json:"Q,omitempty"`
}
type
TestType2
struct
{
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
}
type
ExternalTestType2
struct
{
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
}
type
ExternalTestType1
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
B
int
`json:"B,omitempty"`
C
int8
`json:"C,omitempty"`
D
int16
`json:"D,omitempty"`
E
int32
`json:"E,omitempty"`
F
int64
`json:"F,omitempty"`
G
uint
`json:"G,omitempty"`
H
uint8
`json:"H,omitempty"`
I
uint16
`json:"I,omitempty"`
J
uint32
`json:"J,omitempty"`
K
uint64
`json:"K,omitempty"`
L
bool
`json:"L,omitempty"`
M
map
[
string
]
int
`json:"M,omitempty"`
N
map
[
string
]
ExternalTestType2
`json:"N,omitempty"`
O
*
ExternalTestType2
`json:"O,omitempty"`
P
[]
ExternalTestType2
`json:"Q,omitempty"`
}
type
ExternalInternalSame
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
TestType2
`json:"A,omitempty"`
}
type
UnversionedType
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
}
type
UnknownType
struct
{
MyWeirdCustomEmbeddedVersionKindField
`json:",inline"`
A
string
`json:"A,omitempty"`
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
GetObjectKind
()
schema
.
ObjectKind
{
return
obj
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
SetGroupVersionKind
(
gvk
schema
.
GroupVersionKind
)
{
obj
.
APIVersion
,
obj
.
ObjectKind
=
gvk
.
ToAPIVersionAndKind
()
}
func
(
obj
*
MyWeirdCustomEmbeddedVersionKindField
)
GroupVersionKind
()
schema
.
GroupVersionKind
{
return
schema
.
FromAPIVersionAndKind
(
obj
.
APIVersion
,
obj
.
ObjectKind
)
}
func
(
obj
*
TestType2
)
GetObjectKind
()
schema
.
ObjectKind
{
return
schema
.
EmptyObjectKind
}
func
(
obj
*
ExternalTestType2
)
GetObjectKind
()
schema
.
ObjectKind
{
return
schema
.
EmptyObjectKind
}
func
(
obj
*
InternalComplex
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExternalComplex
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
EmbeddedTest
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
EmbeddedTestExternal
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
InternalSimple
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExternalSimple
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
InternalOptionalExtensionType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ObjectTestExternal
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ObjectTest
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExternalOptionalExtensionType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
InternalExtensionType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExternalExtensionType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExtensionA
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
ExtensionB
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
View file @
205cd90d
...
@@ -174,30 +174,21 @@ func addGrouplessTypes() {
...
@@ -174,30 +174,21 @@ func addGrouplessTypes() {
}
}
func
addTestTypes
()
{
func
addTestTypes
()
{
type
ListOptions
struct
{
Object
runtime
.
Object
metav1
.
TypeMeta
`json:",inline"`
LabelSelector
string
`json:"labelSelector,omitempty"`
FieldSelector
string
`json:"fieldSelector,omitempty"`
Watch
bool
`json:"watch,omitempty"`
ResourceVersion
string
`json:"resourceVersion,omitempty"`
TimeoutSeconds
*
int64
`json:"timeoutSeconds,omitempty"`
}
scheme
.
AddKnownTypes
(
testGroupVersion
,
scheme
.
AddKnownTypes
(
testGroupVersion
,
&
genericapitesting
.
Simple
{},
&
genericapitesting
.
SimpleList
{},
&
metav1
.
ExportOptions
{},
&
genericapitesting
.
Simple
{},
&
genericapitesting
.
SimpleList
{},
&
metav1
.
ExportOptions
{},
&
metav1
.
DeleteOptions
{},
&
genericapitesting
.
SimpleGetOptions
{},
&
genericapitesting
.
SimpleRoot
{},
&
metav1
.
DeleteOptions
{},
&
genericapitesting
.
SimpleGetOptions
{},
&
genericapitesting
.
SimpleRoot
{},
&
SimpleXGSubresource
{})
&
genericapitesting
.
SimpleXGSubresource
{})
scheme
.
AddKnownTypes
(
testGroupVersion
,
&
examplev1
.
Pod
{})
scheme
.
AddKnownTypes
(
testGroupVersion
,
&
examplev1
.
Pod
{})
scheme
.
AddKnownTypes
(
testInternalGroupVersion
,
scheme
.
AddKnownTypes
(
testInternalGroupVersion
,
&
genericapitesting
.
Simple
{},
&
genericapitesting
.
SimpleList
{},
&
metav1
.
ExportOptions
{},
&
genericapitesting
.
Simple
{},
&
genericapitesting
.
SimpleList
{},
&
metav1
.
ExportOptions
{},
&
genericapitesting
.
SimpleGetOptions
{},
&
genericapitesting
.
SimpleRoot
{},
&
genericapitesting
.
SimpleGetOptions
{},
&
genericapitesting
.
SimpleRoot
{},
&
SimpleXGSubresource
{})
&
genericapitesting
.
SimpleXGSubresource
{})
scheme
.
AddKnownTypes
(
testInternalGroupVersion
,
&
example
.
Pod
{})
scheme
.
AddKnownTypes
(
testInternalGroupVersion
,
&
example
.
Pod
{})
// Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their
// Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their
// their corresponding internal versions, to verify that the desired group version object is
// their corresponding internal versions, to verify that the desired group version object is
// served in the tests.
// served in the tests.
scheme
.
AddKnownTypes
(
testGroup2Version
,
&
SimpleXGSubresource
{},
&
metav1
.
ExportOptions
{})
scheme
.
AddKnownTypes
(
testGroup2Version
,
&
genericapitesting
.
SimpleXGSubresource
{},
&
metav1
.
ExportOptions
{})
scheme
.
AddKnownTypes
(
testInternalGroup2Version
,
&
SimpleXGSubresource
{},
&
metav1
.
ExportOptions
{})
scheme
.
AddKnownTypes
(
testInternalGroup2Version
,
&
genericapitesting
.
SimpleXGSubresource
{},
&
metav1
.
ExportOptions
{})
metav1
.
AddToGroupVersion
(
scheme
,
testGroupVersion
)
metav1
.
AddToGroupVersion
(
scheme
,
testGroupVersion
)
}
}
...
@@ -1153,10 +1144,10 @@ func TestList(t *testing.T) {
...
@@ -1153,10 +1144,10 @@ func TestList(t *testing.T) {
t
.
Errorf
(
"%d: %q unexpected resource namespace: %s"
,
i
,
testCase
.
url
,
simpleStorage
.
actualNamespace
)
t
.
Errorf
(
"%d: %q unexpected resource namespace: %s"
,
i
,
testCase
.
url
,
simpleStorage
.
actualNamespace
)
}
}
if
simpleStorage
.
requestedLabelSelector
==
nil
||
simpleStorage
.
requestedLabelSelector
.
String
()
!=
testCase
.
label
{
if
simpleStorage
.
requestedLabelSelector
==
nil
||
simpleStorage
.
requestedLabelSelector
.
String
()
!=
testCase
.
label
{
t
.
Errorf
(
"%d: unexpected label selector:
%v"
,
i
,
simpleStorage
.
requestedLabelSelector
)
t
.
Errorf
(
"%d: unexpected label selector:
expected=%v got=%v"
,
i
,
testCase
.
label
,
simpleStorage
.
requestedLabelSelector
)
}
}
if
simpleStorage
.
requestedFieldSelector
==
nil
||
simpleStorage
.
requestedFieldSelector
.
String
()
!=
testCase
.
field
{
if
simpleStorage
.
requestedFieldSelector
==
nil
||
simpleStorage
.
requestedFieldSelector
.
String
()
!=
testCase
.
field
{
t
.
Errorf
(
"%d: unexpected field selector:
%v"
,
i
,
simpleStorage
.
requestedFieldSelector
)
t
.
Errorf
(
"%d: unexpected field selector:
expected=%v got=%v"
,
i
,
testCase
.
field
,
simpleStorage
.
requestedFieldSelector
)
}
}
}
}
}
}
...
@@ -3935,23 +3926,12 @@ func TestUpdateChecksAPIVersion(t *testing.T) {
...
@@ -3935,23 +3926,12 @@ func TestUpdateChecksAPIVersion(t *testing.T) {
}
}
}
}
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
// same group as its parent resource.
type
SimpleXGSubresource
struct
{
metav1
.
TypeMeta
`json:",inline"`
metav1
.
ObjectMeta
`json:"metadata"`
SubresourceInfo
string
`json:"subresourceInfo,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty"`
}
func
(
obj
*
SimpleXGSubresource
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
type
SimpleXGSubresourceRESTStorage
struct
{
type
SimpleXGSubresourceRESTStorage
struct
{
item
SimpleXGSubresource
item
genericapitesting
.
SimpleXGSubresource
}
}
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
New
()
runtime
.
Object
{
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
New
()
runtime
.
Object
{
return
&
SimpleXGSubresource
{}
return
&
genericapitesting
.
SimpleXGSubresource
{}
}
}
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
Get
(
ctx
request
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
Get
(
ctx
request
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
...
@@ -3969,7 +3949,7 @@ func TestXGSubresource(t *testing.T) {
...
@@ -3969,7 +3949,7 @@ func TestXGSubresource(t *testing.T) {
itemID
:=
"theID"
itemID
:=
"theID"
subresourceStorage
:=
&
SimpleXGSubresourceRESTStorage
{
subresourceStorage
:=
&
SimpleXGSubresourceRESTStorage
{
item
:
SimpleXGSubresource
{
item
:
genericapitesting
.
SimpleXGSubresource
{
SubresourceInfo
:
"foo"
,
SubresourceInfo
:
"foo"
,
},
},
}
}
...
@@ -4018,7 +3998,7 @@ func TestXGSubresource(t *testing.T) {
...
@@ -4018,7 +3998,7 @@ func TestXGSubresource(t *testing.T) {
if
resp
.
StatusCode
!=
http
.
StatusOK
{
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatalf
(
"unexpected response: %#v"
,
resp
)
t
.
Fatalf
(
"unexpected response: %#v"
,
resp
)
}
}
var
itemOut
SimpleXGSubresource
var
itemOut
genericapitesting
.
SimpleXGSubresource
body
,
err
:=
extractBody
(
resp
,
&
itemOut
)
body
,
err
:=
extractBody
(
resp
,
&
itemOut
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
...
@@ -4030,7 +4010,7 @@ func TestXGSubresource(t *testing.T) {
...
@@ -4030,7 +4010,7 @@ func TestXGSubresource(t *testing.T) {
// conversion type list in API scheme and hence cannot be converted from input type object
// conversion type list in API scheme and hence cannot be converted from input type object
// to output type object. So it's values don't appear in the decoded output object.
// to output type object. So it's values don't appear in the decoded output object.
decoder
:=
json
.
NewDecoder
(
strings
.
NewReader
(
body
))
decoder
:=
json
.
NewDecoder
(
strings
.
NewReader
(
body
))
var
itemFromBody
SimpleXGSubresource
var
itemFromBody
genericapitesting
.
SimpleXGSubresource
err
=
decoder
.
Decode
(
&
itemFromBody
)
err
=
decoder
.
Decode
(
&
itemFromBody
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected JSON decoding error: %v"
,
err
)
t
.
Errorf
(
"unexpected JSON decoding error: %v"
,
err
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/openapi/openapi_test.go
View file @
205cd90d
...
@@ -25,27 +25,9 @@ import (
...
@@ -25,27 +25,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema
"
openapitesting
"k8s.io/apiserver/pkg/endpoints/openapi/testing
"
)
)
type
TestType
struct
{
}
func
(
t
TestType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
t
}
func
(
t
TestType
)
SetGroupVersionKind
(
kind
schema
.
GroupVersionKind
)
{
}
func
(
t
TestType
)
GroupVersionKind
()
schema
.
GroupVersionKind
{
return
schema
.
GroupVersionKind
{
Group
:
"test"
,
Version
:
"v1"
,
Kind
:
"TestType"
,
}
}
func
assertEqual
(
t
*
testing
.
T
,
expected
,
actual
interface
{})
{
func
assertEqual
(
t
*
testing
.
T
,
expected
,
actual
interface
{})
{
var
equal
bool
var
equal
bool
if
expected
==
nil
||
actual
==
nil
{
if
expected
==
nil
||
actual
==
nil
{
...
@@ -59,17 +41,17 @@ func assertEqual(t *testing.T, expected, actual interface{}) {
...
@@ -59,17 +41,17 @@ func assertEqual(t *testing.T, expected, actual interface{}) {
}
}
func
TestGetDefinitionName
(
t
*
testing
.
T
)
{
func
TestGetDefinitionName
(
t
*
testing
.
T
)
{
testType
:=
TestType
{}
testType
:=
openapitesting
.
TestType
{}
// in production, the name is stripped of ".*vendor/" prefix before passed
// in production, the name is stripped of ".*vendor/" prefix before passed
// to GetDefinitionName, so here typePkgName does not have the
// to GetDefinitionName, so here typePkgName does not have the
// "k8s.io/kubernetes/vendor" prefix.
// "k8s.io/kubernetes/vendor" prefix.
typePkgName
:=
"k8s.io/apiserver/pkg/endpoints/openapi.TestType"
typePkgName
:=
"k8s.io/apiserver/pkg/endpoints/openapi
/testing
.TestType"
typeFriendlyName
:=
"io.k8s.apiserver.pkg.endpoints.openapi.TestType"
typeFriendlyName
:=
"io.k8s.apiserver.pkg.endpoints.openapi.
testing.
TestType"
if
strings
.
HasSuffix
(
reflect
.
TypeOf
(
testType
)
.
PkgPath
(),
"go_default_test"
)
{
if
strings
.
HasSuffix
(
reflect
.
TypeOf
(
testType
)
.
PkgPath
(),
"go_default_test"
)
{
// the test is running inside bazel where the package name is changed and
// the test is running inside bazel where the package name is changed and
// "go_default_test" will add to package path.
// "go_default_test" will add to package path.
typePkgName
=
"k8s.io/apiserver/pkg/endpoints/openapi/go_default_test.TestType"
typePkgName
=
"k8s.io/apiserver/pkg/endpoints/openapi/
testing/
go_default_test.TestType"
typeFriendlyName
=
"io.k8s.apiserver.pkg.endpoints.openapi.go_default_test.TestType"
typeFriendlyName
=
"io.k8s.apiserver.pkg.endpoints.openapi.
testing.
go_default_test.TestType"
}
}
s
:=
runtime
.
NewScheme
()
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypeWithName
(
testType
.
GroupVersionKind
(),
&
testType
)
s
.
AddKnownTypeWithName
(
testType
.
GroupVersionKind
(),
&
testType
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/openapi/testing/types.go
0 → 100644
View file @
205cd90d
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
testing
import
(
"k8s.io/apimachinery/pkg/runtime/schema"
)
// +k8s:deepcopy-gen=true
type
TestType
struct
{
}
func
(
t
TestType
)
GetObjectKind
()
schema
.
ObjectKind
{
return
t
}
func
(
t
TestType
)
SetGroupVersionKind
(
kind
schema
.
GroupVersionKind
)
{
}
func
(
t
TestType
)
GroupVersionKind
()
schema
.
GroupVersionKind
{
return
schema
.
GroupVersionKind
{
Group
:
"test"
,
Version
:
"v1"
,
Kind
:
"TestType"
,
}
}
staging/src/k8s.io/apiserver/pkg/endpoints/openapi/testing/zz_generated.deepcopy.go
0 → 100644
View file @
205cd90d
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package
testing
import
(
conversion
"k8s.io/apimachinery/pkg/conversion"
reflect
"reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func
GetGeneratedDeepCopyFuncs
()
[]
conversion
.
GeneratedDeepCopyFunc
{
return
[]
conversion
.
GeneratedDeepCopyFunc
{
{
Fn
:
DeepCopy_openapi_TestType
,
InType
:
reflect
.
TypeOf
(
&
TestType
{})},
}
}
// DeepCopy_openapi_TestType is an autogenerated deepcopy function.
func
DeepCopy_openapi_TestType
(
in
interface
{},
out
interface
{},
c
*
conversion
.
Cloner
)
error
{
{
in
:=
in
.
(
*
TestType
)
out
:=
out
.
(
*
TestType
)
*
out
=
*
in
return
nil
}
}
staging/src/k8s.io/apiserver/pkg/endpoints/testing/doc.go
0 → 100644
View file @
205cd90d
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +k8s:deepcopy-gen=package
package
testing
// import "k8s.io/apiserver/pkg/endpoints/testing"
staging/src/k8s.io/apiserver/pkg/endpoints/testing/types.go
View file @
205cd90d
...
@@ -67,3 +67,14 @@ type SimpleList struct {
...
@@ -67,3 +67,14 @@ type SimpleList struct {
}
}
func
(
obj
*
SimpleList
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
func
(
obj
*
SimpleList
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
// same group as its parent resource.
type
SimpleXGSubresource
struct
{
metav1
.
TypeMeta
`json:",inline"`
metav1
.
ObjectMeta
`json:"metadata"`
SubresourceInfo
string
`json:"subresourceInfo,omitempty"`
Labels
map
[
string
]
string
`json:"labels,omitempty"`
}
func
(
obj
*
SimpleXGSubresource
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
obj
.
TypeMeta
}
staging/src/k8s.io/apiserver/pkg/storage/testing/doc.go
0 → 100644
View file @
205cd90d
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +k8s:deepcopy-gen=package
package
testing
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