@@ -19,43 +19,67 @@ package v1alpha2
1919import (
2020 . "github.com/onsi/ginkgo/v2"
2121 . "github.com/onsi/gomega"
22+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
24+ etosv1alpha1 "github.com/eiffel-community/etos/api/v1alpha1"
2325 etosv1alpha2 "github.com/eiffel-community/etos/api/v1alpha2"
24- // TODO (user): Add any additional imports if needed
2526)
2627
2728var _ = Describe ("Iut Webhook" , func () {
2829 var (
2930 obj * etosv1alpha2.Iut
3031 oldObj * etosv1alpha2.Iut
3132 defaulter IutCustomDefaulter
33+
34+ requestID = "89224612-3851-45c9-95c0-72b719ae46ea"
35+ requestIdentifier = "fbb4096d-6529-4c39-bac3-08a7e45bf69a"
36+ requestName = "test-environment-request"
37+ requestLabelCluster = "cluster-sample"
38+ providerID = "iut-provider-sample"
3239 )
3340
3441 BeforeEach (func () {
42+ environmentRequest := etosv1alpha1.EnvironmentRequest {
43+ ObjectMeta : v1.ObjectMeta {
44+ Labels : map [string ]string {
45+ "etos.eiffel-community.github.io/cluster" : requestLabelCluster ,
46+ },
47+ },
48+ Spec : etosv1alpha1.EnvironmentRequestSpec {
49+ Identifier : requestIdentifier ,
50+ Name : requestName ,
51+ ID : requestID ,
52+ },
53+ }
3554 obj = & etosv1alpha2.Iut {}
3655 oldObj = & etosv1alpha2.Iut {}
37- defaulter = IutCustomDefaulter {}
56+ defaulter = IutCustomDefaulter {FakeReader ( & environmentRequest , nil ) }
3857 Expect (defaulter ).NotTo (BeNil (), "Expected defaulter to be initialized" )
3958 Expect (oldObj ).NotTo (BeNil (), "Expected oldObj to be initialized" )
4059 Expect (obj ).NotTo (BeNil (), "Expected obj to be initialized" )
41- // TODO (user): Add any setup logic common to all tests
4260 })
4361
4462 AfterEach (func () {
45- // TODO (user): Add any teardown logic common to all tests
4663 })
4764
4865 Context ("When creating Iut under Defaulting Webhook" , func () {
49- // TODO (user): Add logic for defaulting webhooks
50- // Example:
51- // It("Should apply defaults when a required field is empty", func() {
52- // By("simulating a scenario where defaults should be applied")
53- // obj.SomeFieldWithDefault = ""
54- // By("calling the Default method to apply defaults")
55- // defaulter.Default(ctx, obj)
56- // By("checking that the default values are set")
57- // Expect(obj.SomeFieldWithDefault).To(Equal("default_value"))
58- // })
66+ It ("Should apply defaults when a required field is empty" , func () {
67+ By ("simulating a scenario where defaults should be applied" )
68+ obj .Labels = nil
69+ obj .Spec .ProviderID = providerID
70+ By ("calling the Default method to apply defaults" )
71+ defaulter .Default (ctx , obj )
72+ By ("checking that the default values are set" )
73+ Expect (obj .Labels ).To (Equal (map [string ]string {
74+ "etos.eiffel-community.github.io/environment-request" : requestName ,
75+ "etos.eiffel-community.github.io/environment-request-id" : requestID ,
76+ "etos.eiffel-community.github.io/cluster" : requestLabelCluster ,
77+ "etos.eiffel-community.github.io/provider" : providerID ,
78+ "etos.eiffel-community.github.io/id" : requestIdentifier ,
79+ "app.kubernetes.io/part-of" : "etos" ,
80+ "app.kubernetes.io/name" : "iut-provider" ,
81+ }))
82+ })
5983 })
6084
6185})
0 commit comments