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
c92b4255
Commit
c92b4255
authored
Jun 03, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9217 from caesarxuchao/add-v1-tests-to-pkg/kubectl/cmd
add v1 tests to kubectl/cmd/*
parents
ab1e3cc7
8885025d
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 @
c92b4255
...
...
@@ -118,26 +118,38 @@ func TestPodAndContainer(t *testing.T) {
func
TestExec
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
,
version
,
podPath
,
execPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
execErr
bool
}{
{
name
:
"v1beta3 - pod exec"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
nsInQuery
:
false
,
pod
:
execPod
(),
name
:
"v1beta3 - pod exec"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
pod
:
execPod
(),
},
{
name
:
"v1beta3 - pod exec error"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
nsInQuery
:
false
,
pod
:
execPod
(),
execErr
:
true
,
name
:
"v1beta3 - pod exec error"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
execPath
:
"/api/v1beta3/namespaces/test/pods/foo/exec"
,
pod
:
execPod
(),
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
{
...
...
@@ -147,11 +159,6 @@ func TestExec(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
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
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
...
...
pkg/kubectl/cmd/log_test.go
View file @
c92b4255
...
...
@@ -153,16 +153,21 @@ func TestLog(t *testing.T) {
tests
:=
[]
struct
{
name
,
version
,
podPath
,
logPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
}{
{
name
:
"v1beta3 - pod log"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
logPath
:
"/api/v1beta3/namespaces/test/pods/foo/log"
,
nsInQuery
:
false
,
pod
:
testPod
(),
name
:
"v1beta3 - pod log"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
logPath
:
"/api/v1beta3/namespaces/test/pods/foo/log"
,
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
{
...
...
@@ -173,19 +178,9 @@ func TestLog(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
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
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
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
))
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
...
...
pkg/kubectl/cmd/portforward_test.go
View file @
c92b4255
...
...
@@ -41,26 +41,38 @@ func TestPortForward(t *testing.T) {
tests
:=
[]
struct
{
name
,
version
,
podPath
,
pfPath
,
container
string
nsInQuery
bool
pod
*
api
.
Pod
pfErr
bool
}{
{
name
:
"v1beta3 - pod portforward"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
nsInQuery
:
false
,
pod
:
execPod
(),
name
:
"v1beta3 - pod portforward"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
pod
:
execPod
(),
},
{
name
:
"v1beta3 - pod portforward error"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
nsInQuery
:
false
,
pod
:
execPod
(),
pfErr
:
true
,
name
:
"v1beta3 - pod portforward error"
,
version
:
"v1beta3"
,
podPath
:
"/api/v1beta3/namespaces/test/pods/foo"
,
pfPath
:
"/api/v1beta3/namespaces/test/pods/foo/portforward"
,
pod
:
execPod
(),
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
{
...
...
@@ -70,11 +82,6 @@ func TestPortForward(t *testing.T) {
Client
:
client
.
HTTPClientFunc
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
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
)
return
&
http
.
Response
{
StatusCode
:
200
,
Body
:
body
},
nil
default
:
...
...
pkg/kubectl/cmd/util/helpers_test.go
View file @
c92b4255
...
...
@@ -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
{
...
...
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