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
de1f2c83
Commit
de1f2c83
authored
May 08, 2018
by
hangaoshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor hard code in rest_test.go
parent
e6b6e5c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
107 deletions
+35
-107
rest_test.go
.../src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go
+35
-107
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go
View file @
de1f2c83
...
@@ -499,38 +499,17 @@ func TestPatchResourceNumberConversion(t *testing.T) {
...
@@ -499,38 +499,17 @@ func TestPatchResourceNumberConversion(t *testing.T) {
expectedPod
:
&
example
.
Pod
{},
expectedPod
:
&
example
.
Pod
{},
}
}
tc
.
startingPod
.
Name
=
name
setTcPod
(
tc
.
startingPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
""
)
tc
.
startingPod
.
Namespace
=
namespace
tc
.
startingPod
.
UID
=
uid
tc
.
startingPod
.
ResourceVersion
=
"1"
tc
.
startingPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
startingPod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
// Patch tries to change to 30.
// Patch tries to change to 30.
tc
.
changedPod
.
Name
=
name
setTcPod
(
tc
.
changedPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
thirty
,
""
)
tc
.
changedPod
.
Namespace
=
namespace
tc
.
changedPod
.
UID
=
uid
tc
.
changedPod
.
ResourceVersion
=
"1"
tc
.
changedPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
changedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
// Someone else already changed it to 30.
// Someone else already changed it to 30.
// This should be fine since it's not a "meaningful conflict".
// This should be fine since it's not a "meaningful conflict".
// Previously this was detected as a meaningful conflict because int64(30) != float64(30).
// Previously this was detected as a meaningful conflict because int64(30) != float64(30).
tc
.
updatePod
.
Name
=
name
setTcPod
(
tc
.
updatePod
,
name
,
namespace
,
uid
,
"2"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
thirty
,
"anywhere"
)
tc
.
updatePod
.
Namespace
=
namespace
tc
.
updatePod
.
UID
=
uid
tc
.
updatePod
.
ResourceVersion
=
"2"
tc
.
updatePod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
updatePod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
updatePod
.
Spec
.
NodeName
=
"anywhere"
tc
.
expectedPod
.
Name
=
name
setTcPod
(
tc
.
expectedPod
,
name
,
namespace
,
uid
,
"2"
,
""
,
&
thirty
,
"anywhere"
)
tc
.
expectedPod
.
Namespace
=
namespace
tc
.
expectedPod
.
UID
=
uid
tc
.
expectedPod
.
ResourceVersion
=
"2"
tc
.
expectedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
expectedPod
.
Spec
.
NodeName
=
"anywhere"
tc
.
Run
(
t
)
tc
.
Run
(
t
)
}
}
...
@@ -552,34 +531,13 @@ func TestPatchResourceWithVersionConflict(t *testing.T) {
...
@@ -552,34 +531,13 @@ func TestPatchResourceWithVersionConflict(t *testing.T) {
expectedPod
:
&
example
.
Pod
{},
expectedPod
:
&
example
.
Pod
{},
}
}
tc
.
startingPod
.
Name
=
name
setTcPod
(
tc
.
startingPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
""
)
tc
.
startingPod
.
Namespace
=
namespace
tc
.
startingPod
.
UID
=
uid
tc
.
startingPod
.
ResourceVersion
=
"1"
tc
.
startingPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
startingPod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
changedPod
.
Name
=
name
setTcPod
(
tc
.
changedPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
thirty
,
""
)
tc
.
changedPod
.
Namespace
=
namespace
tc
.
changedPod
.
UID
=
uid
tc
.
changedPod
.
ResourceVersion
=
"1"
tc
.
changedPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
changedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
updatePod
.
Name
=
name
setTcPod
(
tc
.
updatePod
,
name
,
namespace
,
uid
,
"2"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
"anywhere"
)
tc
.
updatePod
.
Namespace
=
namespace
tc
.
updatePod
.
UID
=
uid
tc
.
updatePod
.
ResourceVersion
=
"2"
tc
.
updatePod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
updatePod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
updatePod
.
Spec
.
NodeName
=
"anywhere"
tc
.
expectedPod
.
Name
=
name
setTcPod
(
tc
.
expectedPod
,
name
,
namespace
,
uid
,
"2"
,
""
,
&
thirty
,
"anywhere"
)
tc
.
expectedPod
.
Namespace
=
namespace
tc
.
expectedPod
.
UID
=
uid
tc
.
expectedPod
.
ResourceVersion
=
"2"
tc
.
expectedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
expectedPod
.
Spec
.
NodeName
=
"anywhere"
tc
.
Run
(
t
)
tc
.
Run
(
t
)
}
}
...
@@ -667,26 +625,11 @@ func TestPatchResourceWithConflict(t *testing.T) {
...
@@ -667,26 +625,11 @@ func TestPatchResourceWithConflict(t *testing.T) {
// See issue #63104 for discussion of how much sense this makes.
// See issue #63104 for discussion of how much sense this makes.
tc
.
startingPod
.
Name
=
name
setTcPod
(
tc
.
startingPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
nil
,
"here"
)
tc
.
startingPod
.
Namespace
=
namespace
tc
.
startingPod
.
UID
=
uid
tc
.
startingPod
.
ResourceVersion
=
"1"
tc
.
startingPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
startingPod
.
Spec
.
NodeName
=
"here"
tc
.
changedPod
.
Name
=
name
setTcPod
(
tc
.
changedPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
nil
,
"there"
)
tc
.
changedPod
.
Namespace
=
namespace
tc
.
changedPod
.
UID
=
uid
tc
.
changedPod
.
ResourceVersion
=
"1"
tc
.
changedPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
changedPod
.
Spec
.
NodeName
=
"there"
tc
.
updatePod
.
Name
=
name
setTcPod
(
tc
.
updatePod
,
name
,
namespace
,
uid
,
"2"
,
examplev1
.
SchemeGroupVersion
.
String
(),
nil
,
"anywhere"
)
tc
.
updatePod
.
Namespace
=
namespace
tc
.
updatePod
.
UID
=
uid
tc
.
updatePod
.
ResourceVersion
=
"2"
tc
.
updatePod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
updatePod
.
Spec
.
NodeName
=
"anywhere"
tc
.
expectedPod
.
Name
=
name
tc
.
expectedPod
.
Name
=
name
tc
.
expectedPod
.
Namespace
=
namespace
tc
.
expectedPod
.
Namespace
=
namespace
...
@@ -752,26 +695,11 @@ func TestPatchWithAdmissionRejection(t *testing.T) {
...
@@ -752,26 +695,11 @@ func TestPatchWithAdmissionRejection(t *testing.T) {
expectedError
:
test
.
expectedError
,
expectedError
:
test
.
expectedError
,
}
}
tc
.
startingPod
.
Name
=
name
setTcPod
(
tc
.
startingPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
""
)
tc
.
startingPod
.
Namespace
=
namespace
tc
.
startingPod
.
UID
=
uid
setTcPod
(
tc
.
changedPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
thirty
,
""
)
tc
.
startingPod
.
ResourceVersion
=
"1"
tc
.
startingPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
setTcPod
(
tc
.
updatePod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
""
)
tc
.
startingPod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
changedPod
.
Name
=
name
tc
.
changedPod
.
Namespace
=
namespace
tc
.
changedPod
.
UID
=
uid
tc
.
changedPod
.
ResourceVersion
=
"1"
tc
.
changedPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
changedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
updatePod
.
Name
=
name
tc
.
updatePod
.
Namespace
=
namespace
tc
.
updatePod
.
UID
=
uid
tc
.
updatePod
.
ResourceVersion
=
"1"
tc
.
updatePod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
updatePod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
Run
(
t
)
tc
.
Run
(
t
)
}
}
...
@@ -804,27 +732,11 @@ func TestPatchWithVersionConflictThenAdmissionFailure(t *testing.T) {
...
@@ -804,27 +732,11 @@ func TestPatchWithVersionConflictThenAdmissionFailure(t *testing.T) {
expectedError
:
"admission failure"
,
expectedError
:
"admission failure"
,
}
}
tc
.
startingPod
.
Name
=
name
setTcPod
(
tc
.
startingPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
""
)
tc
.
startingPod
.
Namespace
=
namespace
tc
.
startingPod
.
UID
=
uid
tc
.
startingPod
.
ResourceVersion
=
"1"
tc
.
startingPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
startingPod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
changedPod
.
Name
=
name
setTcPod
(
tc
.
changedPod
,
name
,
namespace
,
uid
,
"1"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
thirty
,
""
)
tc
.
changedPod
.
Namespace
=
namespace
tc
.
changedPod
.
UID
=
uid
tc
.
changedPod
.
ResourceVersion
=
"1"
tc
.
changedPod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
changedPod
.
Spec
.
ActiveDeadlineSeconds
=
&
thirty
tc
.
updatePod
.
Name
=
name
setTcPod
(
tc
.
updatePod
,
name
,
namespace
,
uid
,
"2"
,
examplev1
.
SchemeGroupVersion
.
String
(),
&
fifteen
,
"anywhere"
)
tc
.
updatePod
.
Namespace
=
namespace
tc
.
updatePod
.
UID
=
uid
tc
.
updatePod
.
ResourceVersion
=
"2"
tc
.
updatePod
.
APIVersion
=
examplev1
.
SchemeGroupVersion
.
String
()
tc
.
updatePod
.
Spec
.
ActiveDeadlineSeconds
=
&
fifteen
tc
.
updatePod
.
Spec
.
NodeName
=
"anywhere"
tc
.
Run
(
t
)
tc
.
Run
(
t
)
}
}
...
@@ -922,3 +834,19 @@ func TestFinishRequest(t *testing.T) {
...
@@ -922,3 +834,19 @@ func TestFinishRequest(t *testing.T) {
}
}
}
}
}
}
func
setTcPod
(
tcPod
*
example
.
Pod
,
name
string
,
namespace
string
,
uid
types
.
UID
,
resourceVersion
string
,
apiVersion
string
,
activeDeadlineSeconds
*
int64
,
nodeName
string
)
{
tcPod
.
Name
=
name
tcPod
.
Namespace
=
namespace
tcPod
.
UID
=
uid
tcPod
.
ResourceVersion
=
resourceVersion
if
len
(
apiVersion
)
!=
0
{
tcPod
.
APIVersion
=
apiVersion
}
if
activeDeadlineSeconds
!=
nil
{
tcPod
.
Spec
.
ActiveDeadlineSeconds
=
activeDeadlineSeconds
}
if
len
(
nodeName
)
!=
0
{
tcPod
.
Spec
.
NodeName
=
nodeName
}
}
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