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
412adb8c
Commit
412adb8c
authored
Mar 31, 2019
by
danielqsj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit test for initPolicyFromFile
parent
49c4c6f7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
scheduler_test.go
pkg/scheduler/scheduler_test.go
+93
-0
No files found.
pkg/scheduler/scheduler_test.go
View file @
412adb8c
...
@@ -19,6 +19,9 @@ package scheduler
...
@@ -19,6 +19,9 @@ package scheduler
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
"reflect"
"testing"
"testing"
"time"
"time"
...
@@ -43,6 +46,7 @@ import (
...
@@ -43,6 +46,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
"k8s.io/kubernetes/pkg/scheduler/api"
"k8s.io/kubernetes/pkg/scheduler/api"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
kubeschedulerconfig
"k8s.io/kubernetes/pkg/scheduler/apis/config"
kubeschedulerconfig
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/core"
"k8s.io/kubernetes/pkg/scheduler/core"
"k8s.io/kubernetes/pkg/scheduler/factory"
"k8s.io/kubernetes/pkg/scheduler/factory"
...
@@ -935,3 +939,92 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
...
@@ -935,3 +939,92 @@ func TestSchedulerWithVolumeBinding(t *testing.T) {
})
})
}
}
}
}
func
TestInitPolicyFromFile
(
t
*
testing
.
T
)
{
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"policy"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
defer
os
.
RemoveAll
(
dir
)
for
i
,
test
:=
range
[]
struct
{
policy
string
expectedPredicates
sets
.
String
expectedPrioritizers
sets
.
String
}{
// Test json format policy file
{
policy
:
`{
"kind" : "Policy",
"apiVersion" : "v1",
"predicates" : [
{"name" : "PredicateOne"},
{"name" : "PredicateTwo"}
],
"priorities" : [
{"name" : "PriorityOne", "weight" : 1},
{"name" : "PriorityTwo", "weight" : 5}
]
}`
,
expectedPredicates
:
sets
.
NewString
(
"PredicateOne"
,
"PredicateTwo"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"PriorityOne"
,
"PriorityTwo"
,
),
},
// Test yaml format policy file
{
policy
:
`apiVersion: v1
kind: Policy
predicates:
- name: PredicateOne
- name: PredicateTwo
priorities:
- name: PriorityOne
weight: 1
- name: PriorityTwo
weight: 5
`
,
expectedPredicates
:
sets
.
NewString
(
"PredicateOne"
,
"PredicateTwo"
,
),
expectedPrioritizers
:
sets
.
NewString
(
"PriorityOne"
,
"PriorityTwo"
,
),
},
}
{
file
:=
fmt
.
Sprintf
(
"scheduler-policy-config-file-%d"
,
i
)
fullPath
:=
path
.
Join
(
dir
,
file
)
if
err
:=
ioutil
.
WriteFile
(
fullPath
,
[]
byte
(
test
.
policy
),
0644
);
err
!=
nil
{
t
.
Fatalf
(
"Failed writing a policy config file: %v"
,
err
)
}
policy
:=
&
schedulerapi
.
Policy
{}
if
err
:=
initPolicyFromFile
(
fullPath
,
policy
);
err
!=
nil
{
t
.
Fatalf
(
"Failed writing a policy config file: %v"
,
err
)
}
// Verify that the policy is initialized correctly.
schedPredicates
:=
sets
.
NewString
()
for
_
,
p
:=
range
policy
.
Predicates
{
schedPredicates
.
Insert
(
p
.
Name
)
}
schedPrioritizers
:=
sets
.
NewString
()
for
_
,
p
:=
range
policy
.
Priorities
{
schedPrioritizers
.
Insert
(
p
.
Name
)
}
if
!
schedPredicates
.
Equal
(
test
.
expectedPredicates
)
{
t
.
Errorf
(
"Expected predicates %v, got %v"
,
test
.
expectedPredicates
,
schedPredicates
)
}
if
!
schedPrioritizers
.
Equal
(
test
.
expectedPrioritizers
)
{
t
.
Errorf
(
"Expected priority functions %v, got %v"
,
test
.
expectedPrioritizers
,
schedPrioritizers
)
}
}
}
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