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
635281eb
Commit
635281eb
authored
Feb 06, 2015
by
rsokolowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update guestbook example to use replication controller.
parent
e77322a5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
163 additions
and
162 deletions
+163
-162
examples_test.go
examples/examples_test.go
+1
-1
README.md
examples/guestbook/README.md
+0
-0
frontend-controller.json
examples/guestbook/frontend-controller.json
+4
-3
frontend-service.json
examples/guestbook/frontend-service.json
+4
-3
redis-master-controller.json
examples/guestbook/redis-master-controller.json
+14
-7
redis-slave-controller.json
examples/guestbook/redis-slave-controller.json
+8
-7
redis-slave-service.json
examples/guestbook/redis-slave-service.json
+2
-2
valid-pod.json
examples/limitrange/valid-pod.json
+1
-1
test-cmd.sh
hack/test-cmd.sh
+39
-38
create_test.go
pkg/kubectl/cmd/create_test.go
+15
-17
delete_test.go
pkg/kubectl/cmd/delete_test.go
+19
-21
get_test.go
pkg/kubectl/cmd/get_test.go
+20
-7
update_test.go
pkg/kubectl/cmd/update_test.go
+16
-35
builder_test.go
pkg/kubectl/resource/builder_test.go
+20
-20
No files found.
examples/examples_test.go
View file @
635281eb
...
...
@@ -110,7 +110,7 @@ func TestExampleObjectSchemas(t *testing.T) {
"../examples/guestbook"
:
{
"frontend-controller"
:
&
api
.
ReplicationController
{},
"redis-slave-controller"
:
&
api
.
ReplicationController
{},
"redis-master
"
:
&
api
.
Pod
{},
"redis-master
-controller"
:
&
api
.
ReplicationController
{},
"frontend-service"
:
&
api
.
Service
{},
"redis-master-service"
:
&
api
.
Service
{},
"redis-slave-service"
:
&
api
.
Service
{},
...
...
examples/guestbook/README.md
View file @
635281eb
This diff is collapsed.
Click to expand it.
examples/guestbook/frontend-controller.json
View file @
635281eb
...
...
@@ -9,19 +9,20 @@
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"frontend
-controller
"
,
"id"
:
"frontend"
,
"containers"
:
[{
"name"
:
"php-redis"
,
"image"
:
"kubernetes/example-guestbook-php-redis"
,
"cpu"
:
100
,
"memory"
:
50000000
,
"ports"
:
[{
"
containerPort"
:
80
,
"hostPort"
:
800
0
}]
"ports"
:
[{
"
name"
:
"http-server"
,
"containerPort"
:
8
0
}]
}]
}
},
"labels"
:
{
"name"
:
"frontend"
,
"uses"
:
"redisslave,redis-master"
"uses"
:
"redis-slave,redis-master"
,
"app"
:
"frontend"
}
}},
"labels"
:
{
"name"
:
"frontend"
}
...
...
examples/guestbook/frontend-service.json
View file @
635281eb
...
...
@@ -2,12 +2,13 @@
"id"
:
"frontend"
,
"kind"
:
"Service"
,
"apiVersion"
:
"v1beta1"
,
"port"
:
80
,
"containerPort"
:
80
,
"port"
:
80
00
,
"containerPort"
:
"http-server"
,
"selector"
:
{
"name"
:
"frontend"
},
"labels"
:
{
"name"
:
"frontend"
}
},
"createExternalLoadBalancer"
:
true
}
examples/guestbook/redis-master.json
→
examples/guestbook/redis-master
-controller
.json
View file @
635281eb
{
"id"
:
"redis-master"
,
"kind"
:
"
Pod
"
,
"id"
:
"redis-master
-controller
"
,
"kind"
:
"
ReplicationController
"
,
"apiVersion"
:
"v1beta1"
,
"desiredState"
:
{
"replicas"
:
1
,
"replicaSelector"
:
{
"name"
:
"redis-master"
},
"podTemplate"
:
{
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"redis-master"
,
"containers"
:
[{
"name"
:
"
master"
,
"name"
:
"redis-
master"
,
"image"
:
"dockerfile/redis"
,
"cpu"
:
100
,
"ports"
:
[{
"containerPort"
:
6379
,
"hostPort"
:
6379
}]
"ports"
:
[{
"containerPort"
:
6379
}]
}]
}
},
"labels"
:
{
"name"
:
"redis-master"
,
"app"
:
"redis"
}
}
},
"labels"
:
{
"name"
:
"redis-master"
}
}
...
...
examples/guestbook/redis-slave-controller.json
View file @
635281eb
...
...
@@ -4,25 +4,26 @@
"apiVersion"
:
"v1beta1"
,
"desiredState"
:
{
"replicas"
:
2
,
"replicaSelector"
:
{
"name"
:
"redisslave"
},
"replicaSelector"
:
{
"name"
:
"redis
-
slave"
},
"podTemplate"
:
{
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"redis-slave
-controller
"
,
"id"
:
"redis-slave"
,
"containers"
:
[{
"name"
:
"slave"
,
"name"
:
"
redis-
slave"
,
"image"
:
"brendanburns/redis-slave"
,
"cpu"
:
200
,
"ports"
:
[{
"containerPort"
:
6379
,
"hostPort"
:
6380
}]
"ports"
:
[{
"containerPort"
:
6379
}]
}]
}
},
"labels"
:
{
"name"
:
"redisslave"
,
"uses"
:
"redis-master"
"name"
:
"redis-slave"
,
"uses"
:
"redis-master"
,
"app"
:
"redis"
}
}
},
"labels"
:
{
"name"
:
"redisslave"
}
"labels"
:
{
"name"
:
"redis
-
slave"
}
}
examples/guestbook/redis-slave-service.json
View file @
635281eb
...
...
@@ -5,9 +5,9 @@
"port"
:
6379
,
"containerPort"
:
6379
,
"labels"
:
{
"name"
:
"redisslave"
"name"
:
"redis
-
slave"
},
"selector"
:
{
"name"
:
"redisslave"
"name"
:
"redis
-
slave"
}
}
examples/limitrange/valid-pod.json
View file @
635281eb
...
...
@@ -8,7 +8,7 @@
"desiredState"
:
{
"manifest"
:
{
"version"
:
"v1beta1"
,
"id"
:
"
in
valid-pod"
,
"id"
:
"valid-pod"
,
"containers"
:
[{
"name"
:
"kubernetes-serve-hostname"
,
"image"
:
"kubernetes/serve_hostname"
,
...
...
hack/test-cmd.sh
View file @
635281eb
...
...
@@ -132,67 +132,68 @@ for version in "${kube_api_versions[@]}"; do
kube::log::status
"Testing kubectl(
${
version
}
:pods)"
kubectl get pods
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
guestbook/redis-master
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
limitrange/valid-pod
.json
"
${
kube_flags
[@]
}
"
kubectl get pods
"
${
kube_flags
[@]
}
"
kubectl get pod
redis-master
"
${
kube_flags
[@]
}
"
[
"
$(
kubectl get pod
redis-master
-o
template
--output-version
=
v1beta1
-t
'{{ .id }}'
"
${
kube_flags
[@]
}
"
)
"
==
"redis-master
"
]
output_pod
=
$(
kubectl get pod
redis-master
-o
yaml
--output-version
=
v1beta1
"
${
kube_flags
[@]
}
"
)
kubectl delete pod
redis-master
"
${
kube_flags
[@]
}
"
kubectl get pod
valid-pod
"
${
kube_flags
[@]
}
"
[
"
$(
kubectl get pod
valid-pod
-o
template
--output-version
=
v1beta1
-t
'{{ .id }}'
"
${
kube_flags
[@]
}
"
)
"
==
"valid-pod
"
]
output_pod
=
$(
kubectl get pod
valid-pod
-o
yaml
--output-version
=
v1beta1
"
${
kube_flags
[@]
}
"
)
kubectl delete pod
valid-pod
"
${
kube_flags
[@]
}
"
before
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
echo
"
${
output_pod
}
"
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
after
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$((${
after
}
-
${
before
}))
"
-eq
1
]
kubectl get pods
-o
yaml
--output-version
=
v1beta1
"
${
kube_flags
[@]
}
"
|
grep
-q
"id: redis-master"
kubectl describe pod redis-master
"
${
kube_flags
[@]
}
"
|
grep
-q
'Name:.*redis-master'
kubectl delete
-f
examples/guestbook/redis-master.json
"
${
kube_flags
[@]
}
"
kubectl delete pods
-l
name
=
redis-master
"
${
kube_flags
[@]
}
"
[
!
$(
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
redis-master |
grep
-q
'redis-master'
)
]
kubectl create
-f
examples/guestbook/redis-master.json
"
${
kube_flags
[@]
}
"
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
redis-master |
grep
-q
'redis-master'
kubectl get pods
-o
yaml
--output-version
=
v1beta1
"
${
kube_flags
[@]
}
"
|
grep
-q
"id: valid-pod"
kubectl describe pod valid-pod
"
${
kube_flags
[@]
}
"
|
grep
-q
'Name:.*valid-pod'
kubectl delete
-f
examples/limitrange/valid-pod.json
"
${
kube_flags
[@]
}
"
kubectl delete pods
-l
name
=
valid-pod
"
${
kube_flags
[@]
}
"
[
!
$(
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
valid-pod |
grep
-q
'valid-pod'
)
]
kubectl create
-f
examples/limitrange/valid-pod.json
"
${
kube_flags
[@]
}
"
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
valid-pod |
grep
-q
'valid-pod'
[
!
$(
kubectl delete pods
"
${
kube_flags
[@]
}
"
)
]
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
redis-master |
grep
-q
'redis-master
'
[
!
$(
kubectl delete pods
--all
pods
-l
name
=
redis-master
"
${
kube_flags
[@]
}
"
)
]
# not --all and label selector together
kubectl get pods
"
${
kube_flags
[@]
}
"
-lname
=
valid-pod |
grep
-q
'valid-pod
'
[
!
$(
kubectl delete pods
--all
pods
-l
name
=
valid-pod
"
${
kube_flags
[@]
}
"
)
]
# not --all and label selector together
kubectl delete
--all
pods
"
${
kube_flags
[@]
}
"
# --all remove all the pods
kubectl create
-f
examples/
guestbook/redis-master
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
limitrange/valid-pod
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/redis/redis-proxy.yaml
"
${
kube_flags
[@]
}
"
kubectl get pods
redis-master
redis-proxy
"
${
kube_flags
[@]
}
"
kubectl delete pods
redis-master redis-proxy
# delete multiple pods at once
kubectl get pods
valid-pod
redis-proxy
"
${
kube_flags
[@]
}
"
kubectl delete pods
valid-pod redis-proxy
"
${
kube_flags
[@]
}
"
# delete multiple pods at once
howmanypods
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
0
]
kubectl create
-f
examples/
guestbook/redis-master
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
limitrange/valid-pod
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/redis/redis-proxy.yaml
"
${
kube_flags
[@]
}
"
kubectl stop pods
redis-master redis-proxy
# stop multiple pods at once
kubectl stop pods
valid-pod redis-proxy
"
${
kube_flags
[@]
}
"
# stop multiple pods at once
howmanypods
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
0
]
kubectl create
-f
examples/
guestbook/redis-master
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
limitrange/valid-pod
.json
"
${
kube_flags
[@]
}
"
howmanypods
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
1
]
#testing pods and label command command
kubectl label pods
redis-master new-name
=
new-redis-master
"
${
kube_flags
[@]
}
"
kubectl delete pods
-lnew-name
=
new-
redis-master
"
${
kube_flags
[@]
}
"
kubectl label pods
valid-pod new-name
=
new-valid-pod
"
${
kube_flags
[@]
}
"
kubectl delete pods
-lnew-name
=
new-
valid-pod
"
${
kube_flags
[@]
}
"
howmanypods
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
0
]
kubectl create
-f
examples/
guestbook/redis-master
.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/
limitrange/valid-pod
.json
"
${
kube_flags
[@]
}
"
howmanypods
=
"
$(
kubectl get pods
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
1
]
!
$(
kubectl label pods
redis-master
name
=
redis
-super-sayan
"
${
kube_flags
[@]
}
"
)
kubectl label
--overwrite
pods
redis-master
name
=
redis
-super-sayan
"
${
kube_flags
[@]
}
"
kubectl delete pods
-lname
=
redis
-super-sayan
"
${
kube_flags
[@]
}
"
howmanypods
=
"
$(
kubectl get pods
-lname
=
redis
-super-sayan
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
!
$(
kubectl label pods
valid-pod
name
=
valid-pod
-super-sayan
"
${
kube_flags
[@]
}
"
)
kubectl label
--overwrite
pods
valid-pod
name
=
valid-pod
-super-sayan
"
${
kube_flags
[@]
}
"
kubectl delete pods
-lname
=
valid-pod
-super-sayan
"
${
kube_flags
[@]
}
"
howmanypods
=
"
$(
kubectl get pods
-lname
=
valid-pod
-super-sayan
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$howmanypods
"
-eq
0
]
# make calls in another namespace
kubectl create
--namespace
=
other
-f
examples/guestbook/redis-master.json
"
${
kube_flags
[@]
}
"
kubectl get
pod
--namespace
=
other redis-master
kubectl delete
pod
--namespace
=
other redis-master
kubectl create
"
${
kube_flags
[@]
}
"
--namespace
=
other
-f
examples/limitrange/valid-pod.json
kubectl get
"
${
kube_flags
[@]
}
"
pod
--namespace
=
other valid-pod
kubectl delete
"
${
kube_flags
[@]
}
"
pod
--namespace
=
other valid-pod
kube::log::status
"Testing kubectl(
${
version
}
:services)"
kubectl get services
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/
frontend
-service.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/
redis-master
-service.json
"
${
kube_flags
[@]
}
"
kubectl get services
"
${
kube_flags
[@]
}
"
output_service
=
$(
kubectl get service
frontend
-o
json
--output-version
=
v1beta3
"
${
kube_flags
[@]
}
"
)
kubectl delete service
frontend
"
${
kube_flags
[@]
}
"
output_service
=
$(
kubectl get service
redis-master
-o
json
--output-version
=
v1beta3
"
${
kube_flags
[@]
}
"
)
kubectl delete service
redis-master
"
${
kube_flags
[@]
}
"
echo
"
${
output_service
}
"
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
kubectl create
-f
-
"
${
kube_flags
[@]
}
"
<<
__EOF__
{
...
...
@@ -206,15 +207,15 @@ for version in "${kube_api_versions[@]}"; do
}
}
__EOF__
kubectl update service service-
${
version
}
-test
--patch
=
"{
\"
selector
\"
:{
\"
version
\"
:
\"
${
version
}
\"
},
\"
apiVersion
\"
:
\"
${
version
}
\"
}"
kubectl get service
service-
${
version
}
-test
-o
json | kubectl update
-f
-
kubectl update service
"
${
kube_flags
[@]
}
"
service-
${
version
}
-test
--patch
=
"{
\"
selector
\"
:{
\"
version
\"
:
\"
${
version
}
\"
},
\"
apiVersion
\"
:
\"
${
version
}
\"
}"
kubectl get service
"
${
kube_flags
[@]
}
"
service-
${
version
}
-test
-o
json | kubectl update
"
${
kube_flags
[@]
}
"
-f
-
kubectl get services
"
${
kube_flags
[@]
}
"
kubectl get services
"service-
${
version
}
-test"
"
${
kube_flags
[@]
}
"
kubectl delete service
frontend
"
${
kube_flags
[@]
}
"
kubectl delete service
redis-master
"
${
kube_flags
[@]
}
"
servicesbefore
=
"
$(
kubectl get services
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
kubectl create
-f
examples/guestbook/
frontend
-service.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/
redis-master
-service.json
"
${
kube_flags
[@]
}
"
kubectl create
-f
examples/guestbook/redis-slave-service.json
"
${
kube_flags
[@]
}
"
kubectl delete services
frontend redisslave
# delete multiple services at once
kubectl delete services
redis-master redisslave
"
${
kube_flags
[@]
}
"
# delete multiple services at once
servicesafter
=
"
$(
kubectl get services
-o
template
-t
"{{ len .items }}"
"
${
kube_flags
[@]
}
"
)
"
[
"
$((${
servicesafter
}
-
${
servicesbefore
}))
"
-eq
0
]
...
...
pkg/kubectl/cmd/create_test.go
View file @
635281eb
...
...
@@ -25,8 +25,8 @@ import (
)
func
TestCreateObject
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
pods
.
Items
[
0
]
.
Name
=
"redis-mast
er"
_
,
_
,
rc
:=
testData
()
rc
.
Items
[
0
]
.
Name
=
"redis-master-controll
er"
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -34,8 +34,8 @@ func TestCreateObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pod
s"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
replicationcontroller
s"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -46,17 +46,17 @@ func TestCreateObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdCreate
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
// uses the name from the file, not the response
if
buf
.
String
()
!=
"redis-master
\n
"
{
if
buf
.
String
()
!=
"redis-master
-controller
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestCreateMultipleObject
(
t
*
testing
.
T
)
{
pods
,
sv
c
:=
testData
()
_
,
svc
,
r
c
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -64,10 +64,10 @@ func TestCreateMultipleObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/pods"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/services"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/replicationcontrollers"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -78,19 +78,19 @@ func TestCreateMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdCreate
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/frontend-service.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
// Names should come from the REST response, NOT the files
if
buf
.
String
()
!=
"
foo
\n
baz
\n
"
{
if
buf
.
String
()
!=
"
rc1
\n
baz
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestCreateDirectory
(
t
*
testing
.
T
)
{
pods
,
sv
c
:=
testData
()
pods
.
Items
[
0
]
.
Name
=
"redis-master
"
_
,
svc
,
r
c
:=
testData
()
rc
.
Items
[
0
]
.
Name
=
"name
"
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -98,12 +98,10 @@ func TestCreateDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/pods"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/services"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/replicationcontrollers"
&&
m
==
"POST"
:
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
sv
c
.
Items
[
0
])},
nil
return
&
http
.
Response
{
StatusCode
:
201
,
Body
:
objBody
(
codec
,
&
r
c
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -117,7 +115,7 @@ func TestCreateDirectory(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"
baz
\n
baz
\n
baz
\n
redis-master
\n
baz
\n
baz
\n
"
{
if
buf
.
String
()
!=
"
name
\n
baz
\n
name
\n
baz
\n
name
\n
baz
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
pkg/kubectl/cmd/delete_test.go
View file @
635281eb
...
...
@@ -26,7 +26,7 @@ import (
)
func
TestDeleteObject
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
_
,
_
,
rc
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -34,8 +34,8 @@ func TestDeleteObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -46,11 +46,11 @@ func TestDeleteObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdDelete
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
// uses the name from the file, not the response
if
buf
.
String
()
!=
"redis-master
\n
"
{
if
buf
.
String
()
!=
"redis-master
-controller
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
...
...
@@ -62,7 +62,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"DELETE"
:
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
404
,
Body
:
stringBody
(
""
)},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
...
...
@@ -74,7 +74,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdDelete
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
""
{
...
...
@@ -83,7 +83,7 @@ func TestDeleteObjectIgnoreNotFound(t *testing.T) {
}
func
TestDeleteMultipleObject
(
t
*
testing
.
T
)
{
pods
,
sv
c
:=
testData
()
_
,
svc
,
r
c
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -91,8 +91,8 @@ func TestDeleteMultipleObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
default
:
...
...
@@ -105,17 +105,17 @@ func TestDeleteMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdDelete
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/frontend-service.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"redis-master
\n
frontend
\n
"
{
if
buf
.
String
()
!=
"redis-master
-controller
\n
frontend
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestDeleteMultipleObjectIgnoreMissing
(
t
*
testing
.
T
)
{
_
,
svc
:=
testData
()
_
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -123,7 +123,7 @@ func TestDeleteMultipleObjectIgnoreMissing(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"DELETE"
:
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
404
,
Body
:
stringBody
(
""
)},
nil
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
...
...
@@ -137,7 +137,7 @@ func TestDeleteMultipleObjectIgnoreMissing(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdDelete
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/frontend-service.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
...
...
@@ -147,7 +147,7 @@ func TestDeleteMultipleObjectIgnoreMissing(t *testing.T) {
}
func
TestDeleteDirectory
(
t
*
testing
.
T
)
{
pods
,
sv
c
:=
testData
()
_
,
svc
,
r
c
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -155,12 +155,10 @@ func TestDeleteDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/pods/"
)
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/services/"
)
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/replicationcontrollers/"
)
&&
m
==
"DELETE"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
sv
c
.
Items
[
0
])},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
r
c
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -174,13 +172,13 @@ func TestDeleteDirectory(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"frontend-controller
\n
frontend
\n
redis-master
\n
redis-master
\n
redis-slave-controller
\n
redisslave
\n
"
{
if
buf
.
String
()
!=
"frontend-controller
\n
frontend
\n
redis-master
-controller
\n
redis-master
\n
redis-slave-controller
\n
redisslave
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestDeleteMultipleSelector
(
t
*
testing
.
T
)
{
pods
,
svc
:=
testData
()
pods
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
pkg/kubectl/cmd/get_test.go
View file @
635281eb
...
...
@@ -34,7 +34,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch/json"
)
func
testData
()
(
*
api
.
PodList
,
*
api
.
ServiceList
)
{
func
testData
()
(
*
api
.
PodList
,
*
api
.
ServiceList
,
*
api
.
ReplicationControllerList
)
{
pods
:=
&
api
.
PodList
{
ListMeta
:
api
.
ListMeta
{
ResourceVersion
:
"15"
,
...
...
@@ -70,7 +70,20 @@ func testData() (*api.PodList, *api.ServiceList) {
},
},
}
return
pods
,
svc
rc
:=
&
api
.
ReplicationControllerList
{
ListMeta
:
api
.
ListMeta
{
ResourceVersion
:
"17"
,
},
Items
:
[]
api
.
ReplicationController
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"rc1"
,
Namespace
:
"test"
,
ResourceVersion
:
"18"
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
1
,
},
},
},
}
return
pods
,
svc
,
rc
}
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
...
...
@@ -123,7 +136,7 @@ func TestGetSchemaObject(t *testing.T) {
}
func
TestGetObjects
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
pods
,
_
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -149,7 +162,7 @@ func TestGetObjects(t *testing.T) {
}
func
TestGetListObjects
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
pods
,
_
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -175,7 +188,7 @@ func TestGetListObjects(t *testing.T) {
}
func
TestGetMultipleTypeObjects
(
t
*
testing
.
T
)
{
pods
,
svc
:=
testData
()
pods
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -211,7 +224,7 @@ func TestGetMultipleTypeObjects(t *testing.T) {
}
func
TestGetMultipleTypeObjectsAsList
(
t
*
testing
.
T
)
{
pods
,
svc
:=
testData
()
pods
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -260,7 +273,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) {
}
func
TestGetMultipleTypeObjectsWithSelector
(
t
*
testing
.
T
)
{
pods
,
svc
:=
testData
()
pods
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
pkg/kubectl/cmd/update_test.go
View file @
635281eb
...
...
@@ -22,26 +22,11 @@ import (
"strings"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
)
func
rcTestData
()
*
api
.
ReplicationControllerList
{
rc
:=
&
api
.
ReplicationControllerList
{
ListMeta
:
api
.
ListMeta
{
ResourceVersion
:
"17"
,
},
Items
:
[]
api
.
ReplicationController
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"qux"
,
Namespace
:
"test"
,
ResourceVersion
:
"13"
},
},
},
}
return
rc
}
func
TestUpdateObject
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
_
,
_
,
rc
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -49,10 +34,10 @@ func TestUpdateObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
pods/redis-mast
er"
&&
m
==
"PUT"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/
replicationcontrollers/redis-master-controll
er"
&&
m
==
"PUT"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
...
...
@@ -63,17 +48,17 @@ func TestUpdateObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdUpdate
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
// uses the name from the file, not the response
if
buf
.
String
()
!=
"
foo
\n
"
{
if
buf
.
String
()
!=
"
rc1
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestUpdateMultipleObject
(
t
*
testing
.
T
)
{
pods
,
sv
c
:=
testData
()
_
,
svc
,
r
c
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -81,11 +66,10 @@ func TestUpdateMultipleObject(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/pods/redis-master"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/pods/redis-master"
&&
m
==
"PUT"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/replicationcontrollers/redis-master-controller"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/replicationcontrollers/redis-master-controller"
&&
m
==
"PUT"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
rc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"PUT"
:
...
...
@@ -100,18 +84,17 @@ func TestUpdateMultipleObject(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
f
.
NewCmdUpdate
(
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/redis-master
-controller
.json"
)
cmd
.
Flags
()
.
Set
(
"filename"
,
"../../../examples/guestbook/frontend-service.json"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"
foo
\n
baz
\n
"
{
if
buf
.
String
()
!=
"
rc1
\n
baz
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
func
TestUpdateDirectory
(
t
*
testing
.
T
)
{
pods
,
svc
:=
testData
()
rc
:=
rcTestData
()
_
,
svc
,
rc
:=
testData
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
...
...
@@ -119,8 +102,6 @@ func TestUpdateDirectory(t *testing.T) {
Codec
:
codec
,
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/pods/"
)
&&
(
m
==
"GET"
||
m
==
"PUT"
)
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
pods
.
Items
[
0
])},
nil
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/services/"
)
&&
(
m
==
"GET"
||
m
==
"PUT"
)
:
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
objBody
(
codec
,
&
svc
.
Items
[
0
])},
nil
case
strings
.
HasPrefix
(
p
,
"/namespaces/test/replicationcontrollers/"
)
&&
(
m
==
"GET"
||
m
==
"PUT"
)
:
...
...
@@ -139,7 +120,7 @@ func TestUpdateDirectory(t *testing.T) {
cmd
.
Flags
()
.
Set
(
"namespace"
,
"test"
)
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
"
qux
\n
baz
\n
baz
\n
foo
\n
qux
\n
baz
\n
"
{
if
buf
.
String
()
!=
"
rc1
\n
baz
\n
rc1
\n
baz
\n
rc1
\n
baz
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
pkg/kubectl/resource/builder_test.go
View file @
635281eb
...
...
@@ -166,7 +166,7 @@ func (v *testVisitor) Objects() []runtime.Object {
func
TestPathBuilder
(
t
*
testing
.
T
)
{
b
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClient
())
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
test
:=
&
testVisitor
{}
singular
:=
false
...
...
@@ -177,7 +177,7 @@ func TestPathBuilder(t *testing.T) {
}
info
:=
test
.
Infos
[
0
]
if
info
.
Name
!=
"redis-master"
||
info
.
Namespace
!=
""
||
info
.
Object
==
nil
{
if
info
.
Name
!=
"redis-master
-controller
"
||
info
.
Namespace
!=
""
||
info
.
Object
==
nil
{
t
.
Errorf
(
"unexpected info: %#v"
,
info
)
}
}
...
...
@@ -215,8 +215,8 @@ func TestNodeBuilder(t *testing.T) {
func
TestPathBuilderWithMultiple
(
t
*
testing
.
T
)
{
b
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClient
())
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
.
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
test
:=
&
testVisitor
{}
...
...
@@ -228,7 +228,7 @@ func TestPathBuilderWithMultiple(t *testing.T) {
}
info
:=
test
.
Infos
[
1
]
if
info
.
Name
!=
"redis-master"
||
info
.
Namespace
!=
"test"
||
info
.
Object
==
nil
{
if
info
.
Name
!=
"redis-master
-controller
"
||
info
.
Namespace
!=
"test"
||
info
.
Object
==
nil
{
t
.
Errorf
(
"unexpected info: %#v"
,
info
)
}
}
...
...
@@ -248,7 +248,7 @@ func TestDirectoryBuilder(t *testing.T) {
found
:=
false
for
_
,
info
:=
range
test
.
Infos
{
if
info
.
Name
==
"redis-master"
&&
info
.
Namespace
==
"test"
&&
info
.
Object
!=
nil
{
if
info
.
Name
==
"redis-master
-controller
"
&&
info
.
Namespace
==
"test"
&&
info
.
Object
!=
nil
{
found
=
true
}
}
...
...
@@ -474,7 +474,7 @@ func TestMultipleObject(t *testing.T) {
func
TestSingularObject
(
t
*
testing
.
T
)
{
obj
,
err
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClient
())
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
.
Flatten
()
.
Do
()
.
Object
()
...
...
@@ -482,12 +482,12 @@ func TestSingularObject(t *testing.T) {
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
pod
,
ok
:=
obj
.
(
*
api
.
Pod
)
rc
,
ok
:=
obj
.
(
*
api
.
ReplicationController
)
if
!
ok
{
t
.
Fatalf
(
"unexpected object: %#v"
,
obj
)
}
if
pod
.
Name
!=
"redis-master"
||
pod
.
Namespace
!=
"test"
{
t
.
Errorf
(
"unexpected
pod: %#v"
,
pod
)
if
rc
.
Name
!=
"redis-master-controller"
||
rc
.
Namespace
!=
"test"
{
t
.
Errorf
(
"unexpected
controller: %#v"
,
rc
)
}
}
...
...
@@ -550,16 +550,16 @@ func TestListObjectWithDifferentVersions(t *testing.T) {
}
func
TestWatch
(
t
*
testing
.
T
)
{
pods
,
_
:=
testData
()
_
,
svc
:=
testData
()
w
,
err
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClientWith
(
t
,
map
[
string
]
string
{
"/watch/namespaces/test/
pods/redis-master?resourceVersion=10
"
:
watchBody
(
watch
.
Event
{
"/watch/namespaces/test/
services/redis-master?resourceVersion=12
"
:
watchBody
(
watch
.
Event
{
Type
:
watch
.
Added
,
Object
:
&
pods
.
Items
[
0
],
Object
:
&
svc
.
Items
[
0
],
}),
}))
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
Flatten
()
.
Do
()
.
Watch
(
"1
0
"
)
FilenameParam
(
"../../../examples/guestbook/redis-master
-service
.json"
)
.
Flatten
()
.
Do
()
.
Watch
(
"1
2
"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -572,12 +572,12 @@ func TestWatch(t *testing.T) {
if
obj
.
Type
!=
watch
.
Added
{
t
.
Fatalf
(
"unexpected watch event"
,
obj
)
}
pod
,
ok
:=
obj
.
Object
.
(
*
api
.
Pod
)
service
,
ok
:=
obj
.
Object
.
(
*
api
.
Service
)
if
!
ok
{
t
.
Fatalf
(
"unexpected object: %#v"
,
obj
)
}
if
pod
.
Name
!=
"foo"
||
pod
.
ResourceVersion
!=
"10
"
{
t
.
Errorf
(
"unexpected
pod: %#v"
,
pod
)
if
service
.
Name
!=
"baz"
||
service
.
ResourceVersion
!=
"12
"
{
t
.
Errorf
(
"unexpected
service: %#v"
,
service
)
}
}
}
...
...
@@ -585,8 +585,8 @@ func TestWatch(t *testing.T) {
func
TestWatchMultipleError
(
t
*
testing
.
T
)
{
_
,
err
:=
NewBuilder
(
latest
.
RESTMapper
,
api
.
Scheme
,
fakeClient
())
.
NamespaceParam
(
"test"
)
.
DefaultNamespace
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
Flatten
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master.json"
)
.
Flatten
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
.
Flatten
()
.
FilenameParam
(
"../../../examples/guestbook/redis-master
-controller
.json"
)
.
Flatten
()
.
Do
()
.
Watch
(
""
)
if
err
==
nil
{
...
...
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