Skip to content

Scaffold webhook test examples do not use suite_test structure #4442

Open
@mateusoliveira43

Description

@mateusoliveira43

What do you want to happen?

For example, Defaulter webhook was already setup here

err = SetupAdmiralWebhookWithManager(mgr)

And manager started here

But example tells user to manually call Defaulter webhook

// TODO (user): Add logic for defaulting webhooks
// Example:
// It("Should apply defaults when a required field is empty", func() {
// By("simulating a scenario where defaults should be applied")
// obj.SomeFieldWithDefault = ""
// By("calling the Default method to apply defaults")
// defaulter.Default(ctx, obj)
// By("checking that the default values are set")
// Expect(obj.SomeFieldWithDefault).To(Equal("default_value"))
// })

It could be simplified to

It("Should apply defaults when a required field is empty", func() { 
    By("creating a object where defaults should be applied") 
    obj.SomeFieldWithDefault = "" 
    Expect(k8sClient.Create(ctx, obj)).NotTo(HaveOccurred())

    By("checking that the default values are set") 
    Expect(obj.SomeFieldWithDefault).To(Equal("default_value")) 
}) 

Note: scaffold internal/controller/suite_test.go do not start a manager. Instead of changing users examples, another approach would be removing manager start up in webhook suite_test.go, which would be my suggestion.

Extra Labels

/kind cleanup

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.kind/featureCategorizes issue or PR as related to a new feature.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions