Organize framework unit tests in subtests
This commit is contained in:
@@ -1295,14 +1295,16 @@ func TestPodEligibleToPreemptOthers(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
var nodes []*v1.Node
|
||||
for _, n := range test.nodes {
|
||||
nodes = append(nodes, st.MakeNode().Name(n).Obj())
|
||||
}
|
||||
snapshot := internalcache.NewSnapshot(test.pods, nodes)
|
||||
if got := PodEligibleToPreemptOthers(test.pod, snapshot.NodeInfos(), test.nominatedNodeStatus); got != test.expected {
|
||||
t.Errorf("expected %t, got %t for pod: %s", test.expected, got, test.pod.Name)
|
||||
}
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var nodes []*v1.Node
|
||||
for _, n := range test.nodes {
|
||||
nodes = append(nodes, st.MakeNode().Name(n).Obj())
|
||||
}
|
||||
snapshot := internalcache.NewSnapshot(test.pods, nodes)
|
||||
if got := PodEligibleToPreemptOthers(test.pod, snapshot.NodeInfos(), test.nominatedNodeStatus); got != test.expected {
|
||||
t.Errorf("expected %t, got %t for pod: %s", test.expected, got, test.pod.Name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -63,19 +64,21 @@ func TestDefaultNormalizeScore(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
scores := framework.NodeScoreList{}
|
||||
for _, score := range test.scores {
|
||||
scores = append(scores, framework.NodeScore{Score: score})
|
||||
}
|
||||
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||
scores := framework.NodeScoreList{}
|
||||
for _, score := range test.scores {
|
||||
scores = append(scores, framework.NodeScore{Score: score})
|
||||
}
|
||||
|
||||
expectedScores := framework.NodeScoreList{}
|
||||
for _, score := range test.expectedScores {
|
||||
expectedScores = append(expectedScores, framework.NodeScore{Score: score})
|
||||
}
|
||||
expectedScores := framework.NodeScoreList{}
|
||||
for _, score := range test.expectedScores {
|
||||
expectedScores = append(expectedScores, framework.NodeScore{Score: score})
|
||||
}
|
||||
|
||||
DefaultNormalizeScore(framework.MaxNodeScore, test.reverse, scores)
|
||||
if !reflect.DeepEqual(scores, expectedScores) {
|
||||
t.Errorf("test %d, expected %v, got %v", i, expectedScores, scores)
|
||||
}
|
||||
DefaultNormalizeScore(framework.MaxNodeScore, test.reverse, scores)
|
||||
if !reflect.DeepEqual(scores, expectedScores) {
|
||||
t.Errorf("expected %v, got %v", expectedScores, scores)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,10 +281,12 @@ func TestGetContainerPorts(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := getContainerPorts(test.pod1, test.pod2)
|
||||
if !reflect.DeepEqual(test.expected, result) {
|
||||
t.Errorf("Got different result than expected.\nDifference detected on:\n%s", diff.ObjectGoPrintSideBySide(test.expected, result))
|
||||
}
|
||||
for i, test := range tests {
|
||||
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||
result := getContainerPorts(test.pod1, test.pod2)
|
||||
if !reflect.DeepEqual(test.expected, result) {
|
||||
t.Errorf("Got different result than expected.\nDifference detected on:\n%s", diff.ObjectGoPrintSideBySide(test.expected, result))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,8 +635,10 @@ func TestValidateFitArgs(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range argsTest {
|
||||
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
|
||||
t.Errorf("case[%v]: error details do not include %v", test.name, err)
|
||||
}
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if err := validateFitArgs(test.args); err != nil && !strings.Contains(err.Error(), test.expect) {
|
||||
t.Errorf("case[%v]: error details do not include %v", test.name, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package noderesources
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -173,11 +174,13 @@ func TestBrokenLinearFunction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
function := buildBrokenLinearFunction(test.points)
|
||||
for _, assertion := range test.assertions {
|
||||
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%f", test.points, assertion.p)
|
||||
}
|
||||
for i, test := range tests {
|
||||
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
|
||||
function := buildBrokenLinearFunction(test.points)
|
||||
for _, assertion := range test.assertions {
|
||||
assert.InDelta(t, assertion.expected, function(assertion.p), 0.1, "points=%v, p=%f", test.points, assertion.p)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user