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
656fa7be
Commit
656fa7be
authored
Jun 03, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9225 from caesarxuchao/add-v1-tests-general
Add v1 tests
parents
c92b4255
ca72165b
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
46 additions
and
222 deletions
+46
-222
conversion_test.go
pkg/api/conversion_test.go
+0
-1
testapi_test.go
pkg/api/testapi/testapi_test.go
+22
-22
api_installer_test.go
pkg/apiserver/api_installer_test.go
+2
-2
limit_ranges_test.go
pkg/client/limit_ranges_test.go
+0
-3
nodes_test.go
pkg/client/nodes_test.go
+0
-3
persistentvolume_test.go
pkg/client/persistentvolume_test.go
+0
-3
persistentvolumeclaim_test.go
pkg/client/persistentvolumeclaim_test.go
+0
-3
pod_templates_test.go
pkg/client/pod_templates_test.go
+0
-24
events_cache_test.go
pkg/client/record/events_cache_test.go
+3
-3
replication_controllers_test.go
pkg/client/replication_controllers_test.go
+0
-3
resource_quotas_test.go
pkg/client/resource_quotas_test.go
+0
-3
replication_controller_test.go
pkg/controller/replication_controller_test.go
+1
-4
expose_test.go
pkg/kubectl/cmd/expose_test.go
+4
-4
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+3
-3
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+1
-14
common_test.go
pkg/kubelet/config/common_test.go
+7
-7
file_test.go
pkg/kubelet/config/file_test.go
+0
-120
helper_test.go
pkg/runtime/helper_test.go
+1
-0
unstructured_test.go
pkg/runtime/unstructured_test.go
+2
-0
No files found.
pkg/api/conversion_test.go
View file @
656fa7be
...
...
@@ -22,7 +22,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
_
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
)
func
BenchmarkPodConversion
(
b
*
testing
.
B
)
{
...
...
pkg/api/testapi/testapi_test.go
View file @
656fa7be
...
...
@@ -46,9 +46,9 @@ func TestResourcePathWithPrefixForV1Beta3(t *testing.T) {
}
}
func
TestResourcePathWithPrefixForV1
Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1
beta1
"
{
// Skip the test if we are not testing v1
beta1
.
func
TestResourcePathWithPrefixForV1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1"
{
// Skip the test if we are not testing v1.
return
}
...
...
@@ -59,11 +59,11 @@ func TestResourcePathWithPrefixForV1Beta1(t *testing.T) {
name
string
expected
string
}{
{
"prefix"
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
beta1/prefix
/resource/myresource"
},
{
"prefix"
,
"resource"
,
""
,
"myresource"
,
"/api/v1
beta1
/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
""
,
"/api/v1
beta1/prefix
/resource"
},
{
"prefix"
,
"resource"
,
""
,
""
,
"/api/v1
beta1
/prefix/resource"
},
{
""
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
beta1
/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
/prefix/namespaces/mynamespace
/resource/myresource"
},
{
"prefix"
,
"resource"
,
""
,
"myresource"
,
"/api/v1/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
""
,
"/api/v1
/prefix/namespaces/mynamespace
/resource"
},
{
"prefix"
,
"resource"
,
""
,
""
,
"/api/v1/prefix/resource"
},
{
""
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
/namespaces/mynamespace
/resource/myresource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithPrefix
(
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
...
...
@@ -96,9 +96,9 @@ func TestResourcePathForV1Beta3(t *testing.T) {
}
}
func
TestResourcePathForV1
Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1
beta1
"
{
// Skip the test if we are not testing v1
beta1
.
func
TestResourcePathForV1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1"
{
// Skip the test if we are not testing v1.
return
}
...
...
@@ -108,10 +108,10 @@ func TestResourcePathForV1Beta1(t *testing.T) {
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
beta1
/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1
beta1
/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1
beta1
/resource"
},
{
"resource"
,
""
,
""
,
"/api/v1
beta1
/resource"
},
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
/namespaces/mynamespace
/resource/myresource"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1
/namespaces/mynamespace
/resource"
},
{
"resource"
,
""
,
""
,
"/api/v1/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePath
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
...
...
@@ -144,9 +144,9 @@ func TestResourcePathWithNamespaceQueryForV1Beta3(t *testing.T) {
}
}
func
TestResourcePathWithNamespaceQueryForV1
Beta1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1
beta1
"
{
// Skip the test if we are not testing v1
beta1
.
func
TestResourcePathWithNamespaceQueryForV1
(
t
*
testing
.
T
)
{
if
Version
()
!=
"v1"
{
// Skip the test if we are not testing v1.
return
}
...
...
@@ -156,10 +156,10 @@ func TestResourcePathWithNamespaceQueryForV1Beta1(t *testing.T) {
name
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
beta1/resource/myresource?namespace=mynamespa
ce"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1
beta1
/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1
beta1/resource?namespace=mynamespa
ce"
},
{
"resource"
,
""
,
""
,
"/api/v1
beta1
/resource"
},
{
"resource"
,
"mynamespace"
,
"myresource"
,
"/api/v1
/namespaces/mynamespace/resource/myresour
ce"
},
{
"resource"
,
""
,
"myresource"
,
"/api/v1/resource/myresource"
},
{
"resource"
,
"mynamespace"
,
""
,
"/api/v1
/namespaces/mynamespace/resour
ce"
},
{
"resource"
,
""
,
""
,
"/api/v1/resource"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
ResourcePathWithNamespaceQuery
(
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
...
...
pkg/apiserver/api_installer_test.go
View file @
656fa7be
...
...
@@ -28,14 +28,14 @@ import (
func
TestScopeNamingGenerateLink
(
t
*
testing
.
T
)
{
selfLinker
:=
&
setTestSelfLinker
{
t
:
t
,
expectedSet
:
"/api/v1
beta3
/namespaces/other/services/foo"
,
expectedSet
:
"/api/v1/namespaces/other/services/foo"
,
name
:
"foo"
,
namespace
:
"other"
,
}
s
:=
scopeNaming
{
meta
.
RESTScopeNamespace
,
selfLinker
,
"/api/v1
beta3
/namespaces/{namespace}/services/{name}"
,
"/api/v1/namespaces/{namespace}/services/{name}"
,
true
,
}
service
:=
&
api
.
Service
{
...
...
pkg/client/limit_ranges_test.go
View file @
656fa7be
...
...
@@ -28,9 +28,6 @@ import (
)
func
getLimitRangesResourceName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"limitRanges"
}
return
"limitranges"
}
...
...
pkg/client/nodes_test.go
View file @
656fa7be
...
...
@@ -28,9 +28,6 @@ import (
)
func
getNodesResourceName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"minions"
}
return
"nodes"
}
...
...
pkg/client/persistentvolume_test.go
View file @
656fa7be
...
...
@@ -28,9 +28,6 @@ import (
)
func
getPersistentVolumesResoureName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"persistentVolumes"
}
return
"persistentvolumes"
}
...
...
pkg/client/persistentvolumeclaim_test.go
View file @
656fa7be
...
...
@@ -28,9 +28,6 @@ import (
)
func
getPersistentVolumeClaimsResoureName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"persistentVolumeClaims"
}
return
"persistentvolumeclaims"
}
...
...
pkg/client/pod_templates_test.go
View file @
656fa7be
...
...
@@ -31,10 +31,6 @@ func getPodTemplatesResoureName() string {
}
func
TestPodTemplateCreate
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
ns
:=
api
.
NamespaceDefault
podTemplate
:=
api
.
PodTemplate
{
ObjectMeta
:
api
.
ObjectMeta
{
...
...
@@ -58,10 +54,6 @@ func TestPodTemplateCreate(t *testing.T) {
}
func
TestPodTemplateGet
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
ns
:=
api
.
NamespaceDefault
podTemplate
:=
&
api
.
PodTemplate
{
ObjectMeta
:
api
.
ObjectMeta
{
...
...
@@ -85,10 +77,6 @@ func TestPodTemplateGet(t *testing.T) {
}
func
TestPodTemplateList
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
ns
:=
api
.
NamespaceDefault
podTemplateList
:=
&
api
.
PodTemplateList
{
Items
:
[]
api
.
PodTemplate
{
...
...
@@ -114,10 +102,6 @@ func TestPodTemplateList(t *testing.T) {
}
func
TestPodTemplateUpdate
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
ns
:=
api
.
NamespaceDefault
podTemplate
:=
&
api
.
PodTemplate
{
ObjectMeta
:
api
.
ObjectMeta
{
...
...
@@ -136,10 +120,6 @@ func TestPodTemplateUpdate(t *testing.T) {
}
func
TestPodTemplateDelete
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
ns
:=
api
.
NamespaceDefault
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"DELETE"
,
Path
:
testapi
.
ResourcePath
(
getPodTemplatesResoureName
(),
ns
,
"foo"
),
Query
:
buildQueryValues
(
ns
,
nil
)},
...
...
@@ -150,10 +130,6 @@ func TestPodTemplateDelete(t *testing.T) {
}
func
TestPodTemplateWatch
(
t
*
testing
.
T
)
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
c
:=
&
testClient
{
Request
:
testRequest
{
Method
:
"GET"
,
...
...
pkg/client/record/events_cache_test.go
View file @
656fa7be
...
...
@@ -67,7 +67,7 @@ func TestAddOrUpdateEventExisting(t *testing.T) {
Name
:
"anOkName"
,
Namespace
:
"someNamespace"
,
UID
:
"C934D3234CD0242"
,
APIVersion
:
"v
1beta2
"
,
APIVersion
:
"v
ersion
"
,
},
Source
:
api
.
EventSource
{
Component
:
"kubelet"
,
...
...
@@ -88,7 +88,7 @@ func TestAddOrUpdateEventExisting(t *testing.T) {
Name
:
"anOkName"
,
Namespace
:
"someNamespace"
,
UID
:
"C934D3234CD0242"
,
APIVersion
:
"v
1beta2
"
,
APIVersion
:
"v
ersion
"
,
},
Source
:
api
.
EventSource
{
Component
:
"kubelet"
,
...
...
@@ -119,7 +119,7 @@ func TestGetEventNoExisting(t *testing.T) {
Name
:
"iAmAController"
,
Namespace
:
"IHaveANamespace"
,
UID
:
"9039D34AFBCDA42"
,
APIVersion
:
"v
1beta3
"
,
APIVersion
:
"v
ersion
"
,
},
Source
:
api
.
EventSource
{
Component
:
"kubelet"
,
...
...
pkg/client/replication_controllers_test.go
View file @
656fa7be
...
...
@@ -25,9 +25,6 @@ import (
)
func
getRCResourceName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"replicationControllers"
}
return
"replicationcontrollers"
}
...
...
pkg/client/resource_quotas_test.go
View file @
656fa7be
...
...
@@ -28,9 +28,6 @@ import (
)
func
getResourceQuotasResoureName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"resourceQuotas"
}
return
"resourcequotas"
}
...
...
pkg/controller/replication_controller_test.go
View file @
656fa7be
...
...
@@ -166,9 +166,6 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
}
func
replicationControllerResourceName
()
string
{
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
"replicationControllers"
}
return
"replicationcontrollers"
}
...
...
@@ -193,7 +190,7 @@ func makeTestServer(t *testing.T, namespace, name string, podResponse, controlle
mux
:=
http
.
NewServeMux
()
mux
.
Handle
(
testapi
.
ResourcePath
(
"pods"
,
namespace
,
""
),
&
fakePodHandler
)
mux
.
Handle
(
testapi
.
ResourcePath
(
replicationControllerResourceName
(),
""
,
""
),
&
fakeControllerHandler
)
if
!
api
.
PreV1Beta3
(
testapi
.
Version
())
&&
namespace
!=
""
{
if
namespace
!=
""
{
mux
.
Handle
(
testapi
.
ResourcePath
(
replicationControllerResourceName
(),
namespace
,
""
),
&
fakeControllerHandler
)
}
if
name
!=
""
{
...
...
pkg/kubectl/cmd/expose_test.go
View file @
656fa7be
...
...
@@ -49,7 +49,7 @@ func TestRunExposeService(t *testing.T) {
},
input
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"app"
:
"go"
},
},
...
...
@@ -57,7 +57,7 @@ func TestRunExposeService(t *testing.T) {
flags
:
map
[
string
]
string
{
"selector"
:
"func=stream"
,
"protocol"
:
"UDP"
,
"port"
:
"14"
,
"name"
:
"foo"
,
"labels"
:
"svc=test"
},
output
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
,
Labels
:
map
[
string
]
string
{
"svc"
:
"test"
}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{
{
...
...
@@ -82,7 +82,7 @@ func TestRunExposeService(t *testing.T) {
},
input
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"mayor"
,
Namespace
:
"default"
,
ResourceVersion
:
"12"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"run"
:
"this"
},
},
...
...
@@ -91,7 +91,7 @@ func TestRunExposeService(t *testing.T) {
flags
:
map
[
string
]
string
{
"selector"
:
"run=this"
,
"port"
:
"80"
,
"labels"
:
"runas=amayor"
},
output
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"mayor"
,
Namespace
:
"default"
,
ResourceVersion
:
"12"
,
Labels
:
map
[
string
]
string
{
"runas"
:
"amayor"
}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{
{
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
656fa7be
...
...
@@ -117,7 +117,7 @@ func TestLabelsForObject(t *testing.T) {
name
:
"successful re-use of labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
Labels
:
map
[
string
]
string
{
"svc"
:
"test"
}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
},
expected
:
"svc=test"
,
err
:
nil
,
...
...
@@ -126,7 +126,7 @@ func TestLabelsForObject(t *testing.T) {
name
:
"empty labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"test"
,
Labels
:
map
[
string
]
string
{}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
},
expected
:
""
,
err
:
nil
,
...
...
@@ -135,7 +135,7 @@ func TestLabelsForObject(t *testing.T) {
name
:
"nil labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"zen"
,
Namespace
:
"test"
,
Labels
:
nil
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1
beta3
"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
},
},
expected
:
""
,
err
:
nil
,
...
...
pkg/kubectl/resource_printer_test.go
View file @
656fa7be
...
...
@@ -416,20 +416,7 @@ func TestTemplateStrings(t *testing.T) {
}
// The point of this test is to verify that the below template works. If you change this
// template, you need to update hack/e2e-suite/update.sh.
tmpl
:=
``
if
api
.
PreV1Beta3
(
testapi
.
Version
())
{
tmpl
=
`{{exists . "currentState" "info" "foo" "state" "running"}}`
useThisToDebug
:=
`
a: {{exists . "currentState"}}
b: {{exists . "currentState" "info"}}
c: {{exists . "currentState" "info" "foo"}}
d: {{exists . "currentState" "info" "foo" "state"}}
e: {{exists . "currentState" "info" "foo" "state" "running"}}
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
_
=
useThisToDebug
// don't complain about unused var
}
else
{
tmpl
=
`{{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "foo") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`
}
tmpl
:=
`{{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "foo") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`
p
,
err
:=
NewTemplatePrinter
([]
byte
(
tmpl
))
if
err
!=
nil
{
t
.
Fatalf
(
"tmpl fail: %v"
,
err
)
...
...
pkg/kubelet/config/common_test.go
View file @
656fa7be
...
...
@@ -21,6 +21,7 @@ import (
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
...
...
@@ -56,11 +57,6 @@ func TestDecodeSinglePod(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
parsed
,
podOut
,
err
:=
tryDecodeSinglePod
(
json
,
noDefault
)
if
testapi
.
Version
()
==
"v1beta1"
{
// v1beta1 conversion leaves empty lists that should be nil
podOut
.
Spec
.
Containers
[
0
]
.
Resources
.
Limits
=
nil
podOut
.
Spec
.
Containers
[
0
]
.
Resources
.
Requests
=
nil
}
if
!
parsed
{
t
.
Errorf
(
"expected to have parsed file: (%s)"
,
string
(
json
))
}
...
...
@@ -71,7 +67,8 @@ func TestDecodeSinglePod(t *testing.T) {
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
%s"
,
pod
,
podOut
,
string
(
json
))
}
externalPod
,
err
:=
testapi
.
Converter
()
.
ConvertToVersion
(
pod
,
"v1beta3"
)
for
_
,
version
:=
range
registered
.
RegisteredVersions
{
externalPod
,
err
:=
testapi
.
Converter
()
.
ConvertToVersion
(
pod
,
version
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -90,6 +87,7 @@ func TestDecodeSinglePod(t *testing.T) {
if
!
reflect
.
DeepEqual
(
pod
,
podOut
)
{
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
%s"
,
pod
,
podOut
,
string
(
yaml
))
}
}
}
func
TestDecodePodList
(
t
*
testing
.
T
)
{
...
...
@@ -137,7 +135,8 @@ func TestDecodePodList(t *testing.T) {
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
%s"
,
podList
,
&
podListOut
,
string
(
json
))
}
externalPodList
,
err
:=
testapi
.
Converter
()
.
ConvertToVersion
(
podList
,
"v1beta3"
)
for
_
,
version
:=
range
registered
.
RegisteredVersions
{
externalPodList
,
err
:=
testapi
.
Converter
()
.
ConvertToVersion
(
podList
,
version
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -156,4 +155,5 @@ func TestDecodePodList(t *testing.T) {
if
!
reflect
.
DeepEqual
(
podList
,
&
podListOut
)
{
t
.
Errorf
(
"expected:
\n
%#v
\n
got:
\n
%#v
\n
%s"
,
pod
,
&
podListOut
,
string
(
yaml
))
}
}
}
pkg/kubelet/config/file_test.go
View file @
656fa7be
...
...
@@ -17,7 +17,6 @@ limitations under the License.
package
config
import
(
"fmt"
"io/ioutil"
"os"
"testing"
...
...
@@ -68,99 +67,6 @@ func writeTestFile(t *testing.T, dir, name string, contents string) *os.File {
return
file
}
func
TestReadContainerManifestFromFile
(
t
*
testing
.
T
)
{
// ContainerManifest is supported only for pre v1beta3 versions.
if
!
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
hostname
:=
"random-test-hostname"
var
testCases
=
[]
struct
{
desc
string
fileContents
string
expected
kubelet
.
PodUpdate
}{
{
desc
:
"Manifest"
,
fileContents
:
fmt
.
Sprintf
(
`{
"version": "%s",
"uuid": "12345",
"id": "test",
"containers": [{ "name": "image", "image": "test/image", "imagePullPolicy": "PullAlways"}]
}`
,
testapi
.
Version
()),
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test-"
+
hostname
,
UID
:
"12345"
,
Namespace
:
kubelet
.
NamespaceDefault
,
SelfLink
:
getSelfLink
(
"test-"
+
hostname
,
kubelet
.
NamespaceDefault
),
},
Spec
:
api
.
PodSpec
{
NodeName
:
hostname
,
RestartPolicy
:
api
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
Containers
:
[]
api
.
Container
{{
Name
:
"image"
,
Image
:
"test/image"
,
TerminationMessagePath
:
"/dev/termination-log"
,
ImagePullPolicy
:
"Always"
,
SecurityContext
:
securitycontext
.
ValidSecurityContextWithContainerDefaults
()}},
},
}),
},
{
desc
:
"Manifest without ID"
,
fileContents
:
fmt
.
Sprintf
(
`{
"version": "%s",
"uuid": "12345",
"containers": [{ "name": "image", "image": "test/image", "imagePullPolicy": "PullAlways"}]
}`
,
testapi
.
Version
()),
expected
:
CreatePodUpdate
(
kubelet
.
SET
,
kubelet
.
FileSource
,
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"12345-"
+
hostname
,
UID
:
"12345"
,
Namespace
:
kubelet
.
NamespaceDefault
,
SelfLink
:
getSelfLink
(
"12345-"
+
hostname
,
kubelet
.
NamespaceDefault
),
},
Spec
:
api
.
PodSpec
{
NodeName
:
hostname
,
RestartPolicy
:
api
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
Containers
:
[]
api
.
Container
{{
Name
:
"image"
,
Image
:
"test/image"
,
TerminationMessagePath
:
"/dev/termination-log"
,
ImagePullPolicy
:
"Always"
,
SecurityContext
:
securitycontext
.
ValidSecurityContextWithContainerDefaults
()}},
},
}),
},
}
for
_
,
testCase
:=
range
testCases
{
func
()
{
file
:=
writeTestFile
(
t
,
os
.
TempDir
(),
"test_pod_config"
,
testCase
.
fileContents
)
defer
os
.
Remove
(
file
.
Name
())
ch
:=
make
(
chan
interface
{})
NewSourceFile
(
file
.
Name
(),
hostname
,
time
.
Millisecond
,
ch
)
select
{
case
got
:=
<-
ch
:
update
:=
got
.
(
kubelet
.
PodUpdate
)
for
_
,
pod
:=
range
update
.
Pods
{
if
errs
:=
validation
.
ValidatePod
(
pod
);
len
(
errs
)
>
0
{
t
.
Errorf
(
"%s: Invalid pod %#v, %#v"
,
testCase
.
desc
,
pod
,
errs
)
}
}
if
!
api
.
Semantic
.
DeepEqual
(
testCase
.
expected
,
update
)
{
t
.
Errorf
(
"%s: Expected %#v, Got %#v"
,
testCase
.
desc
,
testCase
.
expected
,
update
)
}
case
<-
time
.
After
(
time
.
Second
)
:
t
.
Errorf
(
"%s: Expected update, timeout instead"
,
testCase
.
desc
)
}
}()
}
}
func
TestReadPodsFromFile
(
t
*
testing
.
T
)
{
hostname
:=
"random-test-hostname"
var
testCases
=
[]
struct
{
...
...
@@ -276,32 +182,6 @@ func TestReadPodsFromFile(t *testing.T) {
}
}
func
TestReadManifestFromFileWithDefaults
(
t
*
testing
.
T
)
{
if
!
api
.
PreV1Beta3
(
testapi
.
Version
())
{
return
}
file
:=
writeTestFile
(
t
,
os
.
TempDir
(),
"test_pod_config"
,
fmt
.
Sprintf
(
`{
"version": "%s",
"id": "test",
"containers": [{ "name": "image", "image": "test/image" }]
}`
,
testapi
.
Version
()))
defer
os
.
Remove
(
file
.
Name
())
ch
:=
make
(
chan
interface
{})
NewSourceFile
(
file
.
Name
(),
"localhost"
,
time
.
Millisecond
,
ch
)
select
{
case
got
:=
<-
ch
:
update
:=
got
.
(
kubelet
.
PodUpdate
)
if
update
.
Pods
[
0
]
.
UID
==
""
{
t
.
Errorf
(
"Unexpected UID: %s"
,
update
.
Pods
[
0
]
.
UID
)
}
case
<-
time
.
After
(
time
.
Second
)
:
t
.
Errorf
(
"Expected update, timeout instead"
)
}
}
func
TestExtractFromBadDataFile
(
t
*
testing
.
T
)
{
file
:=
writeTestFile
(
t
,
os
.
TempDir
(),
"test_pod_config"
,
string
([]
byte
{
1
,
2
,
3
}))
defer
os
.
Remove
(
file
.
Name
())
...
...
pkg/runtime/helper_test.go
View file @
656fa7be
...
...
@@ -138,6 +138,7 @@ func TestDecodeList(t *testing.T) {
Items
:
[]
runtime
.
Object
{
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"1"
}},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1beta3"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"test"}}`
)},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"test"}}`
)},
&
runtime
.
Unstructured
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Foo"
,
APIVersion
:
"Bar"
},
Object
:
map
[
string
]
interface
{}{
"test"
:
"value"
}},
},
}
...
...
pkg/runtime/unstructured_test.go
View file @
656fa7be
...
...
@@ -29,6 +29,8 @@ func TestDecodeUnstructured(t *testing.T) {
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"1"
}},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1beta3"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"test"}}`
)},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
""
,
APIVersion
:
"v1beta3"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1beta3","metadata":{"name":"test"}}`
)},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"test"}}`
)},
&
runtime
.
Unknown
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
""
,
APIVersion
:
"v1"
},
RawJSON
:
[]
byte
(
`{"kind":"Pod","apiVersion":"v1","metadata":{"name":"test"}}`
)},
&
runtime
.
Unstructured
{
TypeMeta
:
runtime
.
TypeMeta
{
Kind
:
"Foo"
,
APIVersion
:
"Bar"
},
Object
:
map
[
string
]
interface
{}{
"test"
:
"value"
}},
},
}
...
...
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