Created
December 11, 2025 06:59
-
-
Save aaron-prindle/fe5094a4a7cff827583ed4f8361ff241 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestValidateDeclarativelyWithMigrationChecks(t *testing.T) { | |
| // ... existing setup ... | |
| testCases := []struct { | |
| name string | |
| dvFeatureEnabled bool | |
| takeoverEnabled bool | |
| containsDeclarativeOnly bool | |
| shouldPanic bool // Add this field | |
| imperativeErrors field.ErrorList | |
| declarativeErrors field.ErrorList | |
| expectedErrors field.ErrorList | |
| }{ | |
| // ... existing test cases ... | |
| { | |
| name: "Feature Disabled, contains DeclarativeOnly, Panic -> Returns InternalError (Fail-Closed)", | |
| dvFeatureEnabled: false, | |
| containsDeclarativeOnly: true, | |
| shouldPanic: true, | |
| imperativeErrors: field.ErrorList{}, | |
| // Expectation: The panic should be caught and returned as an InternalError, even if feature gate is off. | |
| expectedErrors: field.ErrorList{ | |
| field.InternalError(nil, fmt.Errorf("validation failed: simulated panic")), | |
| }, | |
| }, | |
| } | |
| for _, tc := range testCases { | |
| t.Run(tc.name, func(t *testing.T) { | |
| // ... feature gate setup ... | |
| localScheme := runtime.NewScheme() | |
| localScheme.AddKnownTypes(schema.GroupVersion{Group: "", Version: "v1"}, &v1.Pod{}) | |
| localScheme.AddValidationFunc(&v1.Pod{}, func(ctx context.Context, op operation.Operation, object, oldObject interface{}) field.ErrorList { | |
| // Trigger panic if requested | |
| if tc.shouldPanic { | |
| panic("simulated panic") | |
| } | |
| return tc.declarativeErrors | |
| }) | |
| // ... rest of the test setup ... | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment