mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #90578 from wccsama/gc-controller-test
use subtests in gc_controller_test.go
This commit is contained in:
commit
434b6fb37f
@ -67,11 +67,13 @@ func TestGCTerminated(t *testing.T) {
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
pods []nameToPhase
|
||||
threshold int
|
||||
deletedPodNames sets.String
|
||||
}{
|
||||
{
|
||||
name: "threshold = 0, disables terminated pod deletion",
|
||||
pods: []nameToPhase{
|
||||
{name: "a", phase: v1.PodFailed},
|
||||
{name: "b", phase: v1.PodSucceeded},
|
||||
@ -81,6 +83,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
deletedPodNames: sets.NewString(),
|
||||
},
|
||||
{
|
||||
name: "threshold = 1, delete pod a which is PodFailed and pod b which is PodSucceeded",
|
||||
pods: []nameToPhase{
|
||||
{name: "a", phase: v1.PodFailed},
|
||||
{name: "b", phase: v1.PodSucceeded},
|
||||
@ -90,6 +93,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
deletedPodNames: sets.NewString("a", "b"),
|
||||
},
|
||||
{
|
||||
name: "threshold = 1, delete pod b which is PodSucceeded",
|
||||
pods: []nameToPhase{
|
||||
{name: "a", phase: v1.PodRunning},
|
||||
{name: "b", phase: v1.PodSucceeded},
|
||||
@ -99,6 +103,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
deletedPodNames: sets.NewString("b"),
|
||||
},
|
||||
{
|
||||
name: "threshold = 1, delete pod a which is PodFailed",
|
||||
pods: []nameToPhase{
|
||||
{name: "a", phase: v1.PodFailed},
|
||||
{name: "b", phase: v1.PodSucceeded},
|
||||
@ -107,6 +112,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
deletedPodNames: sets.NewString("a"),
|
||||
},
|
||||
{
|
||||
name: "threshold = 5, don't delete pod",
|
||||
pods: []nameToPhase{
|
||||
{name: "a", phase: v1.PodFailed},
|
||||
{name: "b", phase: v1.PodSucceeded},
|
||||
@ -117,6 +123,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client := fake.NewSimpleClientset(&v1.NodeList{Items: []v1.Node{*testutil.NewNode("node")}})
|
||||
gcc, podInformer, _ := NewFromClient(client, test.threshold)
|
||||
deletedPodNames := make([]string, 0)
|
||||
@ -144,6 +151,7 @@ func TestGCTerminated(t *testing.T) {
|
||||
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v",
|
||||
i, test.deletedPodNames.List(), deletedPodNames)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -403,6 +411,7 @@ func TestGCUnscheduledTerminating(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client := fake.NewSimpleClientset()
|
||||
gcc, podInformer, _ := NewFromClient(client, -1)
|
||||
deletedPodNames := make([]string, 0)
|
||||
@ -436,5 +445,6 @@ func TestGCUnscheduledTerminating(t *testing.T) {
|
||||
t.Errorf("[%v]pod's deleted expected and actual did not match.\n\texpected: %v\n\tactual: %v, test: %v",
|
||||
i, test.deletedPodNames.List(), deletedPodNames, test.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user