mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 02:38:12 +00:00
[KEP-4817] improve testing
* Test feature-gate enabled/disabled for validation * Test pkg/registry/resource/resourceclaim * Add Data and NetworkData to integration test Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
This commit is contained in:
@@ -598,8 +598,6 @@ func TestValidateClaimUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DRAResourceClaimDeviceStatus, true)
|
||||
|
||||
validAllocatedClaim := validClaim.DeepCopy()
|
||||
validAllocatedClaim.Status = resource.ResourceClaimStatus{
|
||||
Allocation: &resource.AllocationResult{
|
||||
@@ -618,10 +616,11 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
validAllocatedClaimOld.Status.Allocation.Devices.Results[0].AdminAccess = nil // Not required in 1.31.
|
||||
|
||||
scenarios := map[string]struct {
|
||||
adminAccess bool
|
||||
oldClaim *resource.ResourceClaim
|
||||
update func(claim *resource.ResourceClaim) *resource.ResourceClaim
|
||||
wantFailures field.ErrorList
|
||||
adminAccess bool
|
||||
deviceStatusFeatureGate bool
|
||||
oldClaim *resource.ResourceClaim
|
||||
update func(claim *resource.ResourceClaim) *resource.ResourceClaim
|
||||
wantFailures field.ErrorList
|
||||
}{
|
||||
"valid-no-op-update": {
|
||||
oldClaim: validClaim,
|
||||
@@ -1016,6 +1015,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: true,
|
||||
},
|
||||
"invalid-device-status-duplicate": {
|
||||
wantFailures: field.ErrorList{
|
||||
@@ -1038,6 +1038,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: true,
|
||||
},
|
||||
"invalid-network-device-status": {
|
||||
wantFailures: field.ErrorList{
|
||||
@@ -1060,6 +1061,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: true,
|
||||
},
|
||||
"invalid-data-device-status": {
|
||||
wantFailures: field.ErrorList{
|
||||
@@ -1080,6 +1082,7 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: true,
|
||||
},
|
||||
"invalid-device-status-no-device": {
|
||||
wantFailures: field.ErrorList{
|
||||
@@ -1097,12 +1100,92 @@ func TestValidateClaimStatusUpdate(t *testing.T) {
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: true,
|
||||
},
|
||||
"invalid-device-status-duplicate-disabled-feature-gate": {
|
||||
wantFailures: nil,
|
||||
oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
|
||||
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
|
||||
claim = claim.DeepCopy()
|
||||
claim.Status.Devices = []resource.AllocatedDeviceStatus{
|
||||
{
|
||||
Driver: goodName,
|
||||
Pool: goodName,
|
||||
Device: goodName,
|
||||
},
|
||||
{
|
||||
Driver: goodName,
|
||||
Pool: goodName,
|
||||
Device: goodName,
|
||||
},
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: false,
|
||||
},
|
||||
"invalid-network-device-status-disabled-feature-gate": {
|
||||
wantFailures: nil,
|
||||
oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
|
||||
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
|
||||
claim = claim.DeepCopy()
|
||||
claim.Status.Devices = []resource.AllocatedDeviceStatus{
|
||||
{
|
||||
Driver: goodName,
|
||||
Pool: goodName,
|
||||
Device: goodName,
|
||||
NetworkData: &resource.NetworkDeviceData{
|
||||
Addresses: []string{
|
||||
"300.9.8.0/24",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: false,
|
||||
},
|
||||
"invalid-data-device-status-disabled-feature-gate": {
|
||||
wantFailures: nil,
|
||||
oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
|
||||
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
|
||||
claim = claim.DeepCopy()
|
||||
claim.Status.Devices = []resource.AllocatedDeviceStatus{
|
||||
{
|
||||
Driver: goodName,
|
||||
Pool: goodName,
|
||||
Device: goodName,
|
||||
Data: &runtime.RawExtension{
|
||||
Raw: []byte(`foo`),
|
||||
},
|
||||
},
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: false,
|
||||
},
|
||||
"invalid-device-status-no-device-disabled-feature-gate": {
|
||||
wantFailures: nil,
|
||||
oldClaim: func() *resource.ResourceClaim { return validAllocatedClaim }(),
|
||||
update: func(claim *resource.ResourceClaim) *resource.ResourceClaim {
|
||||
claim = claim.DeepCopy()
|
||||
claim.Status.Devices = []resource.AllocatedDeviceStatus{
|
||||
{
|
||||
Driver: "b",
|
||||
Pool: "a",
|
||||
Device: "r",
|
||||
},
|
||||
}
|
||||
return claim
|
||||
},
|
||||
deviceStatusFeatureGate: false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, scenario := range scenarios {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DRAAdminAccess, scenario.adminAccess)
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DRAResourceClaimDeviceStatus, scenario.deviceStatusFeatureGate)
|
||||
|
||||
scenario.oldClaim.ResourceVersion = "1"
|
||||
errs := ValidateResourceClaimStatusUpdate(scenario.update(scenario.oldClaim.DeepCopy()), scenario.oldClaim)
|
||||
assertFailures(t, scenario.wantFailures, errs)
|
||||
|
||||
Reference in New Issue
Block a user