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
014ee7bb
Commit
014ee7bb
authored
Oct 01, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14576 from derekwaynecarr/strategy_job_test
Auto commit by PR queue bot
parents
6c65047a
2cb408d2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
0 deletions
+156
-0
strategy_test.go
pkg/registry/job/strategy_test.go
+156
-0
No files found.
pkg/registry/job/strategy_test.go
0 → 100644
View file @
014ee7bb
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
job
import
(
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/experimental"
)
func
TestJobStrategy
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
if
!
Strategy
.
NamespaceScoped
()
{
t
.
Errorf
(
"Job must be namespace scoped"
)
}
if
Strategy
.
AllowCreateOnUpdate
()
{
t
.
Errorf
(
"Job should not allow create on update"
)
}
validSelector
:=
map
[
string
]
string
{
"a"
:
"b"
}
validPodTemplateSpec
:=
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
validSelector
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyOnFailure
,
DNSPolicy
:
api
.
DNSClusterFirst
,
Containers
:
[]
api
.
Container
{{
Name
:
"abc"
,
Image
:
"image"
,
ImagePullPolicy
:
"IfNotPresent"
}},
},
}
job
:=
&
experimental
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myjob"
,
Namespace
:
api
.
NamespaceDefault
,
},
Spec
:
experimental
.
JobSpec
{
Selector
:
validSelector
,
Template
:
&
validPodTemplateSpec
,
},
Status
:
experimental
.
JobStatus
{
Active
:
11
,
},
}
Strategy
.
PrepareForCreate
(
job
)
if
job
.
Status
.
Active
!=
0
{
t
.
Errorf
(
"Job does not allow setting status on create"
)
}
errs
:=
Strategy
.
Validate
(
ctx
,
job
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"Unexpected error validating %v"
,
errs
)
}
parallelism
:=
10
updatedJob
:=
&
experimental
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"bar"
,
ResourceVersion
:
"4"
},
Spec
:
experimental
.
JobSpec
{
Parallelism
:
&
parallelism
,
},
Status
:
experimental
.
JobStatus
{
Active
:
11
,
},
}
// ensure we do not change status
job
.
Status
.
Active
=
10
Strategy
.
PrepareForUpdate
(
updatedJob
,
job
)
if
updatedJob
.
Status
.
Active
!=
10
{
t
.
Errorf
(
"PrepareForUpdate should have preserved prior version status"
)
}
errs
=
Strategy
.
ValidateUpdate
(
ctx
,
updatedJob
,
job
)
if
len
(
errs
)
==
0
{
t
.
Errorf
(
"Expected a validation error"
)
}
}
func
TestJobStatusStrategy
(
t
*
testing
.
T
)
{
ctx
:=
api
.
NewDefaultContext
()
if
!
StatusStrategy
.
NamespaceScoped
()
{
t
.
Errorf
(
"Job must be namespace scoped"
)
}
if
StatusStrategy
.
AllowCreateOnUpdate
()
{
t
.
Errorf
(
"Job should not allow create on update"
)
}
validSelector
:=
map
[
string
]
string
{
"a"
:
"b"
}
validPodTemplateSpec
:=
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
validSelector
,
},
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicyOnFailure
,
DNSPolicy
:
api
.
DNSClusterFirst
,
Containers
:
[]
api
.
Container
{{
Name
:
"abc"
,
Image
:
"image"
,
ImagePullPolicy
:
"IfNotPresent"
}},
},
}
oldParallelism
:=
10
newParallelism
:=
11
oldJob
:=
&
experimental
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myjob"
,
Namespace
:
api
.
NamespaceDefault
,
ResourceVersion
:
"10"
,
},
Spec
:
experimental
.
JobSpec
{
Selector
:
validSelector
,
Template
:
&
validPodTemplateSpec
,
Parallelism
:
&
oldParallelism
,
},
Status
:
experimental
.
JobStatus
{
Active
:
11
,
},
}
newJob
:=
&
experimental
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"myjob"
,
Namespace
:
api
.
NamespaceDefault
,
ResourceVersion
:
"9"
,
},
Spec
:
experimental
.
JobSpec
{
Selector
:
validSelector
,
Template
:
&
validPodTemplateSpec
,
Parallelism
:
&
newParallelism
,
},
Status
:
experimental
.
JobStatus
{
Active
:
12
,
},
}
StatusStrategy
.
PrepareForUpdate
(
newJob
,
oldJob
)
if
newJob
.
Status
.
Active
!=
12
{
t
.
Errorf
(
"Job status updates must allow changes to job status"
)
}
if
*
newJob
.
Spec
.
Parallelism
!=
10
{
t
.
Errorf
(
"Job status updates must now allow changes to job spec"
)
}
errs
:=
StatusStrategy
.
ValidateUpdate
(
ctx
,
newJob
,
oldJob
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"Unexpected error %v"
,
errs
)
}
if
newJob
.
ResourceVersion
!=
"9"
{
t
.
Errorf
(
"Incoming resource version on update should not be mutated"
)
}
}
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