Skip to content

Instantly share code, notes, and snippets.

@aaron-prindle
Created December 11, 2025 06:59
Show Gist options
  • Select an option

  • Save aaron-prindle/fe5094a4a7cff827583ed4f8361ff241 to your computer and use it in GitHub Desktop.

Select an option

Save aaron-prindle/fe5094a4a7cff827583ed4f8361ff241 to your computer and use it in GitHub Desktop.
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