mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #73809 from mourya007/validation_test
Add missing testcases
This commit is contained in:
commit
8d8157f490
@ -802,7 +802,7 @@ func TestIsValidSysctlPattern(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_validatePSPRunAsUser(t *testing.T) {
|
func TestValidatePSPRunAsUser(t *testing.T) {
|
||||||
var testCases = []struct {
|
var testCases = []struct {
|
||||||
name string
|
name string
|
||||||
runAsUserStrategy policy.RunAsUserStrategyOptions
|
runAsUserStrategy policy.RunAsUserStrategyOptions
|
||||||
@ -829,3 +829,80 @@ func Test_validatePSPRunAsUser(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestValidatePSPFSGroup(t *testing.T) {
|
||||||
|
var testCases = []struct {
|
||||||
|
name string
|
||||||
|
fsGroupStrategy policy.FSGroupStrategyOptions
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{"Invalid FSGroupStrategy", policy.FSGroupStrategyOptions{Rule: policy.FSGroupStrategyType("someInvalidStrategy")}, true},
|
||||||
|
{"FSGroupStrategyMustRunAs", policy.FSGroupStrategyOptions{Rule: policy.FSGroupStrategyMustRunAs}, false},
|
||||||
|
{"FSGroupStrategyMayRunAs", policy.FSGroupStrategyOptions{Rule: policy.FSGroupStrategyMayRunAs, Ranges: []policy.IDRange{{Min: 1, Max: 5}}}, false},
|
||||||
|
{"FSGroupStrategyRunAsAny", policy.FSGroupStrategyOptions{Rule: policy.FSGroupStrategyRunAsAny}, false},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
errList := validatePSPFSGroup(field.NewPath("Status"), &testCase.fsGroupStrategy)
|
||||||
|
actualErrors := len(errList)
|
||||||
|
expectedErrors := 1
|
||||||
|
if !testCase.fail {
|
||||||
|
expectedErrors = 0
|
||||||
|
}
|
||||||
|
if actualErrors != expectedErrors {
|
||||||
|
t.Errorf("In testCase %v, expected %v errors, got %v errors", testCase.name, expectedErrors, actualErrors)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidatePSPSupplementalGroup(t *testing.T) {
|
||||||
|
var testCases = []struct {
|
||||||
|
name string
|
||||||
|
supplementalGroupStrategy policy.SupplementalGroupsStrategyOptions
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{"Invalid SupplementalGroupStrategy", policy.SupplementalGroupsStrategyOptions{Rule: policy.SupplementalGroupsStrategyType("someInvalidStrategy")}, true},
|
||||||
|
{"SupplementalGroupsStrategyMustRunAs", policy.SupplementalGroupsStrategyOptions{Rule: policy.SupplementalGroupsStrategyMustRunAs}, false},
|
||||||
|
{"SupplementalGroupsStrategyMayRunAs", policy.SupplementalGroupsStrategyOptions{Rule: policy.SupplementalGroupsStrategyMayRunAs, Ranges: []policy.IDRange{{Min: 1, Max: 5}}}, false},
|
||||||
|
{"SupplementalGroupsStrategyRunAsAny", policy.SupplementalGroupsStrategyOptions{Rule: policy.SupplementalGroupsStrategyRunAsAny}, false},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
errList := validatePSPSupplementalGroup(field.NewPath("Status"), &testCase.supplementalGroupStrategy)
|
||||||
|
actualErrors := len(errList)
|
||||||
|
expectedErrors := 1
|
||||||
|
if !testCase.fail {
|
||||||
|
expectedErrors = 0
|
||||||
|
}
|
||||||
|
if actualErrors != expectedErrors {
|
||||||
|
t.Errorf("In testCase %v, expected %v errors, got %v errors", testCase.name, expectedErrors, actualErrors)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidatePSPRunAsGroup(t *testing.T) {
|
||||||
|
var testCases = []struct {
|
||||||
|
name string
|
||||||
|
runAsGroup policy.RunAsGroupStrategyOptions
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{"RunAsGroupStrategyMayRunAs", policy.RunAsGroupStrategyOptions{Rule: policy.RunAsGroupStrategyMayRunAs, Ranges: []policy.IDRange{{Min: 1, Max: 5}}}, false},
|
||||||
|
{"RunAsGroupStrategyMustRunAs", policy.RunAsGroupStrategyOptions{Rule: policy.RunAsGroupStrategyMustRunAs, Ranges: []policy.IDRange{{Min: 1, Max: 5}}}, false},
|
||||||
|
{"RunAsGroupStrategyRunAsAny", policy.RunAsGroupStrategyOptions{Rule: policy.RunAsGroupStrategyRunAsAny}, false},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
|
errList := validatePSPRunAsGroup(field.NewPath("Status"), &testCase.runAsGroup)
|
||||||
|
actualErrors := len(errList)
|
||||||
|
expectedErrors := 1
|
||||||
|
if !testCase.fail {
|
||||||
|
expectedErrors = 0
|
||||||
|
}
|
||||||
|
if actualErrors != expectedErrors {
|
||||||
|
t.Errorf("In testCase %v, expected %v errors, got %v errors", testCase.name, expectedErrors, actualErrors)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user