Tests should focus on comprehensive coverage of main logic flows rather than trivial functions, use established testing patterns like TestCommonStruct for end-to-end validation, and maintain proper table-driven test formatting for readability and maintainability.
Key principles:
Example of well-structured test:
tests := []struct {
name string
args args
want ResourceStrategyFit
}{
{
name: "test with cpu and memory resources",
args: args{framework.Arguments{
"ResourceStrategyFitPlusWeight": 10,
"resources": map[string]interface{}{
"cpu": map[string]interface{}{
"type": "MostAllocated",
"weight": 1,
},
"memory": map[string]interface{}{
"type": "LeastAllocated",
"weight": 2,
},
},
}},
want: ResourceStrategyFit{
ResourceStrategyFitWeight: 10,
Resources: map[v1.ResourceName]ResourcesType{
"cpu": {
Type: config.MostAllocated,
Weight: 1,
},
"memory": {
Type: config.LeastAllocated,
Weight: 2,
},
},
},
},
}
For integration tests, use the TestCommonStruct pattern to validate complete scheduling workflows rather than isolated unit tests.
Enter the URL of a public GitHub repository