Skip to content

Commit a2d07a7

Browse files
syscod3claude
andcommitted
test(webhook): add nodeName clear test + compile-time interface assertions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6a05429 commit a2d07a7

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

internal/webhook/v1alpha1/impvm_webhook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828
// ImpVMWebhook implements defaulting and validation for ImpVM.
2929
type ImpVMWebhook struct{}
3030

31+
var (
32+
_ admission.Defaulter[*impdevv1alpha1.ImpVM] = &ImpVMWebhook{}
33+
_ admission.Validator[*impdevv1alpha1.ImpVM] = &ImpVMWebhook{}
34+
)
35+
3136
// Default implements admission.Defaulter[*impdevv1alpha1.ImpVM].
3237
func (w *ImpVMWebhook) Default(_ context.Context, vm *impdevv1alpha1.ImpVM) error {
3338
if vm.Spec.Lifecycle == "" {

internal/webhook/v1alpha1/impvm_webhook_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ func TestImpVMWebhook_ValidateUpdate_NodeNameUnchanged(t *testing.T) {
165165
}
166166
}
167167

168+
func TestImpVMWebhook_ValidateUpdate_NodeNameCannotBeCleared(t *testing.T) {
169+
wh := &ImpVMWebhook{}
170+
old := newVM("my-template", "", "")
171+
old.Spec.NodeName = "node-1"
172+
173+
updated := newVM("my-template", "", "")
174+
updated.Spec.NodeName = "" // attempt to clear — should be rejected
175+
176+
_, err := wh.ValidateUpdate(context.Background(), old, updated)
177+
if err == nil {
178+
t.Fatal("expected error when clearing a set nodeName")
179+
}
180+
}
181+
168182
// --- ValidateDelete tests --------------------------------------------------
169183

170184
func TestImpVMWebhook_ValidateDelete(t *testing.T) {

0 commit comments

Comments
 (0)