mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Merge pull request #21736 from resouer/check-register
Auto commit by PR queue bot
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package priorities
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/util/codeinspector"
|
||||
"k8s.io/kubernetes/plugin/pkg/scheduler"
|
||||
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm"
|
||||
priorityutil "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities/util"
|
||||
@@ -883,3 +885,47 @@ func makeImageNode(node string, status api.NodeStatus) api.Node {
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrioritiesRegistered(t *testing.T) {
|
||||
var functionNames []string
|
||||
|
||||
// Files and directories which priorities may be referenced
|
||||
targetFiles := []string{
|
||||
"./../../algorithmprovider/defaults/defaults.go", // Default algorithm
|
||||
"./../../factory/plugins.go", // Registered in init()
|
||||
}
|
||||
|
||||
// List all golang source files under ./priorities/, excluding test files and sub-directories.
|
||||
files, err := codeinspector.GetSourceCodeFiles(".")
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v when listing files in current directory", err)
|
||||
}
|
||||
|
||||
// Get all public priorities in files.
|
||||
for _, filePath := range files {
|
||||
functions, err := codeinspector.GetPublicFunctions(filePath)
|
||||
if err == nil {
|
||||
functionNames = append(functionNames, functions...)
|
||||
} else {
|
||||
t.Errorf("unexpected error when parsing %s", filePath)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all public priorities are referenced in target files.
|
||||
for _, functionName := range functionNames {
|
||||
args := []string{"-rl", functionName}
|
||||
args = append(args, targetFiles...)
|
||||
|
||||
err := exec.Command("grep", args...).Run()
|
||||
if err != nil {
|
||||
switch err.Error() {
|
||||
case "exit status 2":
|
||||
t.Errorf("unexpected error when checking %s", functionName)
|
||||
case "exit status 1":
|
||||
t.Errorf("priority %s is implemented as public but seems not registered or used in any other place",
|
||||
functionName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user