mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Use t.Run in Job validation tests
Change-Id: I0bc69c59b5ccfc9bb323295fed3478341f7a7b21
This commit is contained in:
parent
b259c92dda
commit
0309b8ac9b
@ -23,7 +23,6 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
|
||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
|
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
|
||||||
@ -100,9 +99,11 @@ func TestValidateJob(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for k, v := range successCases {
|
for k, v := range successCases {
|
||||||
if errs := ValidateJob(&v, corevalidation.PodValidationOptions{}); len(errs) != 0 {
|
t.Run(k, func(t *testing.T) {
|
||||||
t.Errorf("expected success for %s: %v", k, errs)
|
if errs := ValidateJob(&v, corevalidation.PodValidationOptions{}); len(errs) != 0 {
|
||||||
}
|
t.Errorf("Got unexpected validation errors: %v", errs)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
negative := int32(-1)
|
negative := int32(-1)
|
||||||
negative64 := int64(-1)
|
negative64 := int64(-1)
|
||||||
@ -237,29 +238,22 @@ func TestValidateJob(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"spec.ttlSecondsAfterFinished:must be greater than or equal to 0": {
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "myjob",
|
||||||
|
Namespace: metav1.NamespaceDefault,
|
||||||
|
UID: types.UID("1a2b3c"),
|
||||||
|
},
|
||||||
|
Spec: batch.JobSpec{
|
||||||
|
TTLSecondsAfterFinished: &negative,
|
||||||
|
Selector: validGeneratedSelector,
|
||||||
|
Template: validPodTemplateSpecForGenerated,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, setFeature := range []bool{true, false} {
|
for k, v := range errorCases {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TTLAfterFinished, setFeature)()
|
t.Run(k, func(t *testing.T) {
|
||||||
ttlCase := "spec.ttlSecondsAfterFinished:must be greater than or equal to 0"
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.TTLAfterFinished) {
|
|
||||||
errorCases[ttlCase] = batch.Job{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "myjob",
|
|
||||||
Namespace: metav1.NamespaceDefault,
|
|
||||||
UID: types.UID("1a2b3c"),
|
|
||||||
},
|
|
||||||
Spec: batch.JobSpec{
|
|
||||||
TTLSecondsAfterFinished: &negative,
|
|
||||||
Selector: validGeneratedSelector,
|
|
||||||
Template: validPodTemplateSpecForGenerated,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete(errorCases, ttlCase)
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range errorCases {
|
|
||||||
errs := ValidateJob(&v, corevalidation.PodValidationOptions{})
|
errs := ValidateJob(&v, corevalidation.PodValidationOptions{})
|
||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
t.Errorf("expected failure for %s", k)
|
t.Errorf("expected failure for %s", k)
|
||||||
@ -270,7 +264,7 @@ func TestValidateJob(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v, expected: %s", err, k)
|
t.Errorf("unexpected error: %v, expected: %s", err, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user