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
8885025d
Commit
8885025d
authored
Jun 03, 2015
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add v1 tests to tests in kubectl/cmd/*
parent
1845ca88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
202 additions
and
55 deletions
+202
-55
exec_test.go
pkg/kubectl/cmd/exec_test.go
+26
-19
log_test.go
pkg/kubectl/cmd/log_test.go
+12
-17
portforward_test.go
pkg/kubectl/cmd/portforward_test.go
+26
-19
helpers_test.go
pkg/kubectl/cmd/util/helpers_test.go
+138
-0
No files found.
pkg/kubectl/cmd/exec_test.go
View file @
8885025d
...
@@ -118,26 +118,38 @@ func TestPodAndContainer(t *testing.T) {
...
@@ -118,26 +118,38 @@ func TestPodAndContainer(t *testing.T) {
func
TestExec
(
t
*
testing
.
T
)
{
func
TestExec
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
,
version
,
podPath
,
execPath
,
container
string
name
,
version
,
podPath
,
execPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
pod
*
api
.
Pod
execErr
bool
execErr
bool
}{
}{
{
{
name
:
"v1beta3 - pod exec"
,
name
:
"v1beta3 - pod exec"
,
version
:
"v1beta3"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
nsInQuery
:
false
,
pod
:
execPod
(),
pod
:
execPod
(),
},
},
{
{
name
:
"v1beta3 - pod exec error"
,
name
:
"v1beta3 - pod exec error"
,
version
:
"v1beta3"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
nsInQuery
:
false
,
pod
:
execPod
(),
pod
:
execPod
(),
execErr
:
true
,
execErr
:
true
,
},
{
name
:
"v1 - pod exec"
,
version
:
"v1"
,
podPath
:
"/api/v1/namespaces/test/pods/foo"
,
execPath
:
"/api/v1/namespaces/test/pods/foo/exec"
,
pod
:
execPod
(),
},
{
name
:
"v1 - pod exec error"
,
version
:
"v1"
,
podPath
:
"/api/v1/namespaces/test/pods/foo"
,
execPath
:
"/api/v1/namespaces/test/pods/foo/exec"
,
pod
:
execPod
(),
execErr
:
true
,
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
@@ -147,11 +159,6 @@ func TestExec(t *testing.T) {
...
@@ -147,11 +159,6 @@ func TestExec(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
test
.
podPath
&&
m
==
"GET"
:
case
p
==
test
.
podPath
&&
m
==
"GET"
:
if
test
.
nsInQuery
{
if
ns
:=
req
.
URL
.
Query
()
.
Get
(
"namespace"
);
ns
!=
"test"
{
t
.
Errorf
(
"%s: did not get expected namespace: %s
\n
"
,
test
.
name
,
ns
)
}
}
body
:=
objBody
(
codec
,
test
.
pod
)
body
:=
objBody
(
codec
,
test
.
pod
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
default
:
...
...
pkg/kubectl/cmd/log_test.go
View file @
8885025d
...
@@ -153,16 +153,21 @@ func TestLog(t *testing.T) {
...
@@ -153,16 +153,21 @@ func TestLog(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
,
version
,
podPath
,
logPath
,
container
string
name
,
version
,
podPath
,
logPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
pod
*
api
.
Pod
}{
}{
{
{
name
:
"v1beta3 - pod log"
,
name
:
"v1beta3 - pod log"
,
version
:
"v1beta3"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
logPath
:
"/api/v1beta3/namespaces/test/pods/foo/log"
,
logPath
:
"/api/v1beta3/namespaces/test/pods/foo/log"
,
nsInQuery
:
false
,
pod
:
testPod
(),
pod
:
testPod
(),
},
{
name
:
"v1 - pod log"
,
version
:
"v1"
,
podPath
:
"/api/v1/namespaces/test/pods/foo"
,
logPath
:
"/api/v1/namespaces/test/pods/foo/log"
,
pod
:
testPod
(),
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
@@ -173,19 +178,9 @@ func TestLog(t *testing.T) {
...
@@ -173,19 +178,9 @@ func TestLog(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
test
.
podPath
&&
m
==
"GET"
:
case
p
==
test
.
podPath
&&
m
==
"GET"
:
if
test
.
nsInQuery
{
if
ns
:=
req
.
URL
.
Query
()
.
Get
(
"namespace"
);
ns
!=
"test"
{
t
.
Errorf
(
"%s: did not get expected namespace: %s
\n
"
,
test
.
name
,
ns
)
}
}
body
:=
objBody
(
codec
,
test
.
pod
)
body
:=
objBody
(
codec
,
test
.
pod
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
case
p
==
test
.
logPath
&&
m
==
"GET"
:
case
p
==
test
.
logPath
&&
m
==
"GET"
:
if
test
.
nsInQuery
{
if
ns
:=
req
.
URL
.
Query
()
.
Get
(
"namespace"
);
ns
!=
"test"
{
t
.
Errorf
(
"%s: did not get expected namespace: %s
\n
"
,
test
.
name
,
ns
)
}
}
body
:=
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
logContent
))
body
:=
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
logContent
))
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
default
:
...
...
pkg/kubectl/cmd/portforward_test.go
View file @
8885025d
...
@@ -41,26 +41,38 @@ func TestPortForward(t *testing.T) {
...
@@ -41,26 +41,38 @@ func TestPortForward(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
,
version
,
podPath
,
pfPath
,
container
string
name
,
version
,
podPath
,
pfPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
pod
*
api
.
Pod
pfErr
bool
pfErr
bool
}{
}{
{
{
name
:
"v1beta3 - pod portforward"
,
name
:
"v1beta3 - pod portforward"
,
version
:
"v1beta3"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
nsInQuery
:
false
,
pod
:
execPod
(),
pod
:
execPod
(),
},
},
{
{
name
:
"v1beta3 - pod portforward error"
,
name
:
"v1beta3 - pod portforward error"
,
version
:
"v1beta3"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
nsInQuery
:
false
,
pod
:
execPod
(),
pod
:
execPod
(),
pfErr
:
true
,
pfErr
:
true
,
},
{
name
:
"v1 - pod portforward"
,
version
:
"v1"
,
podPath
:
"/api/v1/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1/namespaces/test/pods/foo/portforward"
,
pod
:
execPod
(),
},
{
name
:
"v1 - pod portforward error"
,
version
:
"v1"
,
podPath
:
"/api/v1/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1/namespaces/test/pods/foo/portforward"
,
pod
:
execPod
(),
pfErr
:
true
,
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
@@ -70,11 +82,6 @@ func TestPortForward(t *testing.T) {
...
@@ -70,11 +82,6 @@ func TestPortForward(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
test
.
podPath
&&
m
==
"GET"
:
case
p
==
test
.
podPath
&&
m
==
"GET"
:
if
test
.
nsInQuery
{
if
ns
:=
req
.
URL
.
Query
()
.
Get
(
"namespace"
);
ns
!=
"test"
{
t
.
Errorf
(
"%s: did not get expected namespace: %s
\n
"
,
test
.
name
,
ns
)
}
}
body
:=
objBody
(
codec
,
test
.
pod
)
body
:=
objBody
(
codec
,
test
.
pod
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
default
:
...
...
pkg/kubectl/cmd/util/helpers_test.go
View file @
8885025d
...
@@ -174,6 +174,144 @@ func TestMerge(t *testing.T) {
...
@@ -174,6 +174,144 @@ func TestMerge(t *testing.T) {
},
},
},
},
},
},
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
},
fragment
:
`{ "apiVersion": "v1" }`
,
expected
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
},
},
},
/* TODO: uncomment this test once Merge is updated to use
strategic-merge-patch. See #844.
{
kind: "Pod",
obj: &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Spec: api.PodSpec{
Containers: []api.Container{
api.Container{
Name: "c1",
Image: "red-image",
},
api.Container{
Name: "c2",
Image: "blue-image",
},
},
},
},
fragment: `{ "apiVersion": "v1", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`,
expected: &api.Pod{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Spec: api.PodSpec{
Containers: []api.Container{
api.Container{
Name: "c1",
Image: "green-image",
},
api.Container{
Name: "c2",
Image: "blue-image",
},
},
},
},
}, */
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
},
fragment
:
`{ "apiVersion": "v1", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`
,
expected
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
Name
:
"v1"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}},
},
{
Name
:
"v2"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}},
},
},
RestartPolicy
:
api
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
},
},
},
{
kind
:
"Pod"
,
obj
:
&
api
.
Pod
{},
fragment
:
"invalid json"
,
expected
:
&
api
.
Pod
{},
expectErr
:
true
,
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{},
fragment
:
`{ "apiVersion": "badVersion" }`
,
expectErr
:
true
,
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{},
},
fragment
:
`{ "apiVersion": "v1", "spec": { "ports": [ { "port": 0 } ] } }`
,
expected
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{
{
Protocol
:
api
.
ProtocolTCP
,
Port
:
0
,
},
},
},
},
},
{
kind
:
"Service"
,
obj
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"version"
:
"v1"
,
},
},
},
fragment
:
`{ "apiVersion": "v1", "spec": { "selector": { "version": "v2" } } }`
,
expected
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Selector
:
map
[
string
]
string
{
"version"
:
"v2"
,
},
},
},
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
...
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