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
5589c5b3
Unverified
Commit
5589c5b3
authored
Oct 04, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69401 from seans3/helpers-test-fix
kubectl helpers test: remove core dependencies
parents
c568da3a
b4d513b1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
52 deletions
+73
-52
BUILD
pkg/kubectl/cmd/util/BUILD
+1
-3
helpers_test.go
pkg/kubectl/cmd/util/helpers_test.go
+72
-49
No files found.
pkg/kubectl/cmd/util/BUILD
View file @
5589c5b3
...
@@ -61,9 +61,7 @@ go_test(
...
@@ -61,9 +61,7 @@ go_test(
srcs = ["helpers_test.go"],
srcs = ["helpers_test.go"],
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = [
deps = [
"//pkg/api/testapi:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//pkg/api/testing:go_default_library",
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
...
...
pkg/kubectl/cmd/util/helpers_test.go
View file @
5589c5b3
...
@@ -24,7 +24,7 @@ import (
...
@@ -24,7 +24,7 @@ import (
"syscall"
"syscall"
"testing"
"testing"
"k8s.io/api/core/v1"
corev1
"k8s.io/api/core/v1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
...
@@ -32,15 +32,13 @@ import (
...
@@ -32,15 +32,13 @@ 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/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/kubectl/scheme"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/utils/exec"
"k8s.io/utils/exec"
)
)
func
TestMerge
(
t
*
testing
.
T
)
{
func
TestMerge
(
t
*
testing
.
T
)
{
grace
:=
int64
(
30
)
grace
:=
int64
(
30
)
enableServiceLinks
:=
v1
.
DefaultEnableServiceLinks
enableServiceLinks
:=
core
v1
.
DefaultEnableServiceLinks
tests
:=
[]
struct
{
tests
:=
[]
struct
{
obj
runtime
.
Object
obj
runtime
.
Object
fragment
string
fragment
string
...
@@ -48,33 +46,44 @@ func TestMerge(t *testing.T) {
...
@@ -48,33 +46,44 @@ func TestMerge(t *testing.T) {
expectErr
bool
expectErr
bool
}{
}{
{
{
obj
:
&
api
.
Pod
{
obj
:
&
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
},
},
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s" }`
,
"v1"
),
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s" }`
,
"v1"
),
expected
:
&
api
.
Pod
{
expected
:
&
corev1
.
Pod
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1"
,
},
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
Spec
:
apitesting
.
DeepEqualSafePodSpec
(),
Spec
:
corev1
.
PodSpec
{
RestartPolicy
:
corev1
.
RestartPolicyAlways
,
DNSPolicy
:
corev1
.
DNSClusterFirst
,
TerminationGracePeriodSeconds
:
&
grace
,
SecurityContext
:
&
corev1
.
PodSecurityContext
{},
SchedulerName
:
corev1
.
DefaultSchedulerName
,
EnableServiceLinks
:
&
enableServiceLinks
,
},
},
},
},
},
/* TODO: uncomment this test once Merge is updated to use
/* TODO: uncomment this test once Merge is updated to use
strategic-merge-patch. See #8449.
strategic-merge-patch. See #8449.
{
{
obj: &
api
.Pod{
obj: &
corev1
.Pod{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
},
},
Spec:
api
.PodSpec{
Spec:
corev1
.PodSpec{
Containers: []
api
.Container{
Containers: []
corev1
.Container{
api
.Container{
corev1
.Container{
Name: "c1",
Name: "c1",
Image: "red-image",
Image: "red-image",
},
},
api
.Container{
corev1
.Container{
Name: "c2",
Name: "c2",
Image: "blue-image",
Image: "blue-image",
},
},
...
@@ -82,17 +91,17 @@ func TestMerge(t *testing.T) {
...
@@ -82,17 +91,17 @@ func TestMerge(t *testing.T) {
},
},
},
},
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`, schema.GroupVersion{Group:"", Version: "v1"}.String()),
fragment: fmt.Sprintf(`{ "apiVersion": "%s", "spec": { "containers": [ { "name": "c1", "image": "green-image" } ] } }`, schema.GroupVersion{Group:"", Version: "v1"}.String()),
expected: &
api
.Pod{
expected: &
corev1
.Pod{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
},
},
Spec:
api
.PodSpec{
Spec:
corev1
.PodSpec{
Containers: []
api
.Container{
Containers: []
corev1
.Container{
api
.Container{
corev1
.Container{
Name: "c1",
Name: "c1",
Image: "green-image",
Image: "green-image",
},
},
api
.Container{
corev1
.Container{
Name: "c2",
Name: "c2",
Image: "blue-image",
Image: "blue-image",
},
},
...
@@ -101,59 +110,67 @@ func TestMerge(t *testing.T) {
...
@@ -101,59 +110,67 @@ func TestMerge(t *testing.T) {
},
},
}, */
}, */
{
{
obj
:
&
api
.
Pod
{
obj
:
&
corev1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
},
},
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`
,
"v1"
),
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "volumes": [ {"name": "v1"}, {"name": "v2"} ] } }`
,
"v1"
),
expected
:
&
api
.
Pod
{
expected
:
&
corev1
.
Pod
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Pod"
,
APIVersion
:
"v1"
,
},
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Name
:
"foo"
,
},
},
Spec
:
api
.
PodSpec
{
Spec
:
corev1
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
Volumes
:
[]
corev1
.
Volume
{
{
{
Name
:
"v1"
,
Name
:
"v1"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}},
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{}},
},
},
{
{
Name
:
"v2"
,
Name
:
"v2"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}},
VolumeSource
:
corev1
.
VolumeSource
{
EmptyDir
:
&
corev1
.
EmptyDirVolumeSource
{}},
},
},
},
},
RestartPolicy
:
api
.
RestartPolicyAlways
,
RestartPolicy
:
corev1
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
DNSPolicy
:
corev1
.
DNSClusterFirst
,
TerminationGracePeriodSeconds
:
&
grace
,
TerminationGracePeriodSeconds
:
&
grace
,
SecurityContext
:
&
api
.
PodSecurityContext
{},
SecurityContext
:
&
corev1
.
PodSecurityContext
{},
SchedulerName
:
api
.
DefaultSchedulerName
,
SchedulerName
:
corev1
.
DefaultSchedulerName
,
EnableServiceLinks
:
&
enableServiceLinks
,
EnableServiceLinks
:
&
enableServiceLinks
,
},
},
},
},
},
},
{
{
obj
:
&
api
.
Pod
{},
obj
:
&
corev1
.
Pod
{},
fragment
:
"invalid json"
,
fragment
:
"invalid json"
,
expected
:
&
api
.
Pod
{},
expected
:
&
corev1
.
Pod
{},
expectErr
:
true
,
expectErr
:
true
,
},
},
{
{
obj
:
&
api
.
Service
{},
obj
:
&
corev1
.
Service
{},
fragment
:
`{ "apiVersion": "badVersion" }`
,
fragment
:
`{ "apiVersion": "badVersion" }`
,
expectErr
:
true
,
expectErr
:
true
,
},
},
{
{
obj
:
&
api
.
Service
{
obj
:
&
corev1
.
Service
{
Spec
:
api
.
ServiceSpec
{},
Spec
:
corev1
.
ServiceSpec
{},
},
},
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "ports": [ { "port": 0 } ] } }`
,
"v1"
),
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "ports": [ { "port": 0 } ] } }`
,
"v1"
),
expected
:
&
api
.
Service
{
expected
:
&
corev1
.
Service
{
Spec
:
api
.
ServiceSpec
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
,
},
Spec
:
corev1
.
ServiceSpec
{
SessionAffinity
:
"None"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Type
:
corev1
.
ServiceTypeClusterIP
,
Ports
:
[]
api
.
ServicePort
{
Ports
:
[]
corev1
.
ServicePort
{
{
{
Protocol
:
api
.
ProtocolTCP
,
Protocol
:
corev1
.
ProtocolTCP
,
Port
:
0
,
Port
:
0
,
},
},
},
},
...
@@ -161,18 +178,22 @@ func TestMerge(t *testing.T) {
...
@@ -161,18 +178,22 @@ func TestMerge(t *testing.T) {
},
},
},
},
{
{
obj
:
&
api
.
Service
{
obj
:
&
corev1
.
Service
{
Spec
:
api
.
ServiceSpec
{
Spec
:
corev1
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"version"
:
"v1"
,
"version"
:
"v1"
,
},
},
},
},
},
},
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "selector": { "version": "v2" } } }`
,
"v1"
),
fragment
:
fmt
.
Sprintf
(
`{ "apiVersion": "%s", "spec": { "selector": { "version": "v2" } } }`
,
"v1"
),
expected
:
&
api
.
Service
{
expected
:
&
corev1
.
Service
{
Spec
:
api
.
ServiceSpec
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1"
,
},
Spec
:
corev1
.
ServiceSpec
{
SessionAffinity
:
"None"
,
SessionAffinity
:
"None"
,
Type
:
api
.
ServiceTypeClusterIP
,
Type
:
corev1
.
ServiceTypeClusterIP
,
Selector
:
map
[
string
]
string
{
Selector
:
map
[
string
]
string
{
"version"
:
"v2"
,
"version"
:
"v2"
,
},
},
...
@@ -181,12 +202,14 @@ func TestMerge(t *testing.T) {
...
@@ -181,12 +202,14 @@ func TestMerge(t *testing.T) {
},
},
}
}
codec
:=
runtime
.
NewCodec
(
scheme
.
DefaultJSONEncoder
(),
scheme
.
Codecs
.
UniversalDecoder
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
))
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
out
,
err
:=
Merge
(
testapi
.
Default
.
Codec
()
,
test
.
obj
,
test
.
fragment
)
out
,
err
:=
Merge
(
codec
,
test
.
obj
,
test
.
fragment
)
if
!
test
.
expectErr
{
if
!
test
.
expectErr
{
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"testcase[%d], unexpected error: %v"
,
i
,
err
)
t
.
Errorf
(
"testcase[%d], unexpected error: %v"
,
i
,
err
)
}
else
if
!
apiequality
.
Semantic
.
DeepEqual
(
out
,
test
.
expected
)
{
}
else
if
!
apiequality
.
Semantic
.
DeepEqual
(
test
.
expected
,
out
)
{
t
.
Errorf
(
"
\n\n
testcase[%d]
\n
expected:
\n
%+v
\n
saw:
\n
%+v"
,
i
,
test
.
expected
,
out
)
t
.
Errorf
(
"
\n\n
testcase[%d]
\n
expected:
\n
%+v
\n
saw:
\n
%+v"
,
i
,
test
.
expected
,
out
)
}
}
}
}
...
@@ -205,22 +228,22 @@ type checkErrTestCase struct {
...
@@ -205,22 +228,22 @@ type checkErrTestCase struct {
func
TestCheckInvalidErr
(
t
*
testing
.
T
)
{
func
TestCheckInvalidErr
(
t
*
testing
.
T
)
{
testCheckError
(
t
,
[]
checkErrTestCase
{
testCheckError
(
t
,
[]
checkErrTestCase
{
{
{
errors
.
NewInvalid
(
api
.
Kind
(
"Invalid1"
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field"
),
"single"
,
"details"
)}),
errors
.
NewInvalid
(
corev1
.
SchemeGroupVersion
.
WithKind
(
"Invalid1"
)
.
GroupKind
(
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field"
),
"single"
,
"details"
)}),
"The Invalid1
\"
invalidation
\"
is invalid: field: Invalid value:
\"
single
\"
: details
\n
"
,
"The Invalid1
\"
invalidation
\"
is invalid: field: Invalid value:
\"
single
\"
: details
\n
"
,
DefaultErrorExitCode
,
DefaultErrorExitCode
,
},
},
{
{
errors
.
NewInvalid
(
api
.
Kind
(
"Invalid2"
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field1"
),
"multi1"
,
"details"
),
field
.
Invalid
(
field
.
NewPath
(
"field2"
),
"multi2"
,
"details"
)}),
errors
.
NewInvalid
(
corev1
.
SchemeGroupVersion
.
WithKind
(
"Invalid2"
)
.
GroupKind
(
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field1"
),
"multi1"
,
"details"
),
field
.
Invalid
(
field
.
NewPath
(
"field2"
),
"multi2"
,
"details"
)}),
"The Invalid2
\"
invalidation
\"
is invalid:
\n
* field1: Invalid value:
\"
multi1
\"
: details
\n
* field2: Invalid value:
\"
multi2
\"
: details
\n
"
,
"The Invalid2
\"
invalidation
\"
is invalid:
\n
* field1: Invalid value:
\"
multi1
\"
: details
\n
* field2: Invalid value:
\"
multi2
\"
: details
\n
"
,
DefaultErrorExitCode
,
DefaultErrorExitCode
,
},
},
{
{
errors
.
NewInvalid
(
api
.
Kind
(
"Invalid3"
),
"invalidation"
,
field
.
ErrorList
{}),
errors
.
NewInvalid
(
corev1
.
SchemeGroupVersion
.
WithKind
(
"Invalid3"
)
.
GroupKind
(
),
"invalidation"
,
field
.
ErrorList
{}),
"The Invalid3
\"
invalidation
\"
is invalid"
,
"The Invalid3
\"
invalidation
\"
is invalid"
,
DefaultErrorExitCode
,
DefaultErrorExitCode
,
},
},
{
{
errors
.
NewInvalid
(
api
.
Kind
(
"Invalid4"
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field4"
),
"multi4"
,
"details"
),
field
.
Invalid
(
field
.
NewPath
(
"field4"
),
"multi4"
,
"details"
)}),
errors
.
NewInvalid
(
corev1
.
SchemeGroupVersion
.
WithKind
(
"Invalid4"
)
.
GroupKind
(
),
"invalidation"
,
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"field4"
),
"multi4"
,
"details"
),
field
.
Invalid
(
field
.
NewPath
(
"field4"
),
"multi4"
,
"details"
)}),
"The Invalid4
\"
invalidation
\"
is invalid: field4: Invalid value:
\"
multi4
\"
: details
\n
"
,
"The Invalid4
\"
invalidation
\"
is invalid: field4: Invalid value:
\"
multi4
\"
: details
\n
"
,
DefaultErrorExitCode
,
DefaultErrorExitCode
,
},
},
...
...
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