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
6d87c074
Unverified
Commit
6d87c074
authored
Nov 29, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #63664 from xchapter7x/pkg-scheduler-api-validation
use subtest for table units (pkg/scheduler/api/validation)
parents
06a0ed7f
0acc56a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
validation_test.go
pkg/scheduler/api/validation/validation_test.go
+19
-4
No files found.
pkg/scheduler/api/validation/validation_test.go
View file @
6d87c074
...
@@ -28,44 +28,55 @@ func TestValidatePolicy(t *testing.T) {
...
@@ -28,44 +28,55 @@ func TestValidatePolicy(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
policy
api
.
Policy
policy
api
.
Policy
expected
error
expected
error
name
string
}{
}{
{
{
name
:
"no weight defined in policy"
,
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
}}},
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
}}},
expected
:
errors
.
New
(
"Priority NoWeightPriority should have a positive weight applied to it or it has overflown"
),
expected
:
errors
.
New
(
"Priority NoWeightPriority should have a positive weight applied to it or it has overflown"
),
},
},
{
{
name
:
"policy weight is not positive"
,
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
,
Weight
:
0
}}},
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"NoWeightPriority"
,
Weight
:
0
}}},
expected
:
errors
.
New
(
"Priority NoWeightPriority should have a positive weight applied to it or it has overflown"
),
expected
:
errors
.
New
(
"Priority NoWeightPriority should have a positive weight applied to it or it has overflown"
),
},
},
{
{
name
:
"valid weight priority"
,
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
2
}}},
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
2
}}},
expected
:
nil
,
expected
:
nil
,
},
},
{
{
name
:
"invalid negative weight policy"
,
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
-
2
}}},
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
-
2
}}},
expected
:
errors
.
New
(
"Priority WeightPriority should have a positive weight applied to it or it has overflown"
),
expected
:
errors
.
New
(
"Priority WeightPriority should have a positive weight applied to it or it has overflown"
),
},
},
{
{
name
:
"policy weight exceeds maximum"
,
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
api
.
MaxWeight
}}},
policy
:
api
.
Policy
{
Priorities
:
[]
api
.
PriorityPolicy
{{
Name
:
"WeightPriority"
,
Weight
:
api
.
MaxWeight
}}},
expected
:
errors
.
New
(
"Priority WeightPriority should have a positive weight applied to it or it has overflown"
),
expected
:
errors
.
New
(
"Priority WeightPriority should have a positive weight applied to it or it has overflown"
),
},
},
{
{
name
:
"valid weight in policy extender config"
,
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PrioritizeVerb
:
"prioritize"
,
Weight
:
2
}}},
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PrioritizeVerb
:
"prioritize"
,
Weight
:
2
}}},
expected
:
nil
,
expected
:
nil
,
},
},
{
{
name
:
"invalid negative weight in policy extender config"
,
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PrioritizeVerb
:
"prioritize"
,
Weight
:
-
2
}}},
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PrioritizeVerb
:
"prioritize"
,
Weight
:
-
2
}}},
expected
:
errors
.
New
(
"Priority for extender http://127.0.0.1:8081/extender should have a positive weight applied to it"
),
expected
:
errors
.
New
(
"Priority for extender http://127.0.0.1:8081/extender should have a positive weight applied to it"
),
},
},
{
{
name
:
"valid filter verb and url prefix"
,
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
FilterVerb
:
"filter"
}}},
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
FilterVerb
:
"filter"
}}},
expected
:
nil
,
expected
:
nil
,
},
},
{
{
name
:
"valid preemt verb and urlprefix"
,
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PreemptVerb
:
"preempt"
}}},
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
PreemptVerb
:
"preempt"
}}},
expected
:
nil
,
expected
:
nil
,
},
},
{
{
name
:
"invalid multiple extenders"
,
policy
:
api
.
Policy
{
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
BindVerb
:
"bind"
},
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
BindVerb
:
"bind"
},
...
@@ -74,6 +85,7 @@ func TestValidatePolicy(t *testing.T) {
...
@@ -74,6 +85,7 @@ func TestValidatePolicy(t *testing.T) {
expected
:
errors
.
New
(
"Only one extender can implement bind, found 2"
),
expected
:
errors
.
New
(
"Only one extender can implement bind, found 2"
),
},
},
{
{
name
:
"invalid duplicate extender resource name"
,
policy
:
api
.
Policy
{
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
ManagedResources
:
[]
api
.
ExtenderManagedResource
{{
Name
:
"foo.com/bar"
}}},
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
ManagedResources
:
[]
api
.
ExtenderManagedResource
{{
Name
:
"foo.com/bar"
}}},
...
@@ -82,6 +94,7 @@ func TestValidatePolicy(t *testing.T) {
...
@@ -82,6 +94,7 @@ func TestValidatePolicy(t *testing.T) {
expected
:
errors
.
New
(
"Duplicate extender managed resource name foo.com/bar"
),
expected
:
errors
.
New
(
"Duplicate extender managed resource name foo.com/bar"
),
},
},
{
{
name
:
"invalid extended resource name"
,
policy
:
api
.
Policy
{
policy
:
api
.
Policy
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
ExtenderConfigs
:
[]
api
.
ExtenderConfig
{
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
ManagedResources
:
[]
api
.
ExtenderManagedResource
{{
Name
:
"kubernetes.io/foo"
}}},
{
URLPrefix
:
"http://127.0.0.1:8081/extender"
,
ManagedResources
:
[]
api
.
ExtenderManagedResource
{{
Name
:
"kubernetes.io/foo"
}}},
...
@@ -91,9 +104,11 @@ func TestValidatePolicy(t *testing.T) {
...
@@ -91,9 +104,11 @@ func TestValidatePolicy(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
actual
:=
ValidatePolicy
(
test
.
policy
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
if
fmt
.
Sprint
(
test
.
expected
)
!=
fmt
.
Sprint
(
actual
)
{
actual
:=
ValidatePolicy
(
test
.
policy
)
t
.
Errorf
(
"expected: %s, actual: %s"
,
test
.
expected
,
actual
)
if
fmt
.
Sprint
(
test
.
expected
)
!=
fmt
.
Sprint
(
actual
)
{
}
t
.
Errorf
(
"expected: %s, actual: %s"
,
test
.
expected
,
actual
)
}
})
}
}
}
}
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