@@ -6,21 +6,21 @@ import (
66 controllerruntime "sigs.k8s.io/controller-runtime"
77 gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
88
9- ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1 "
9+ ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2 "
1010)
1111
1212func TestObservabilityPoliciesTargetRefKind (t * testing.T ) {
1313 t .Parallel ()
1414 k8sClient := getKubernetesClient (t )
1515
1616 tests := []struct {
17- spec ngfAPIv1alpha1 .ObservabilityPolicySpec
17+ spec ngfAPIv1alpha2 .ObservabilityPolicySpec
1818 name string
1919 wantErrors []string
2020 }{
2121 {
2222 name : "Validate TargetRef of kind HTTPRoute is allowed" ,
23- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
23+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
2424 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
2525 {
2626 Kind : httpRouteKind ,
@@ -31,7 +31,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
3131 },
3232 {
3333 name : "Validate TargetRef of kind GRPCRoute is allowed" ,
34- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
34+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
3535 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
3636 {
3737 Kind : grpcRouteKind ,
@@ -43,7 +43,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
4343 {
4444 name : "Validate Invalid TargetRef Kind is not allowed" ,
4545 wantErrors : []string {expectedTargetRefMustBeHTTPRouteOrGrpcRouteError },
46- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
46+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
4747 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
4848 {
4949 Kind : invalidKind ,
@@ -55,7 +55,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
5555 {
5656 name : "Validate TCPRoute TargetRef Kind is not allowed" ,
5757 wantErrors : []string {expectedTargetRefMustBeHTTPRouteOrGrpcRouteError },
58- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
58+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
5959 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
6060 {
6161 Kind : tcpRouteKind ,
@@ -67,7 +67,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
6767 {
6868 name : "Validate TargetRef of kind Gateway is allowed" ,
6969 wantErrors : []string {expectedTargetRefMustBeHTTPRouteOrGrpcRouteError },
70- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
70+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
7171 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
7272 {
7373 Kind : gatewayKind ,
@@ -78,7 +78,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
7878 },
7979 {
8080 name : "Validate ObservabilityPolicy is applied when one TargetRef is valid and another is invalid" ,
81- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
81+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
8282 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
8383 {
8484 Kind : gatewayKind ,
@@ -102,7 +102,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) {
102102 spec .TargetRefs [i ].Name = gatewayv1alpha2 .ObjectName (uniqueResourceName (testTargetRefName ))
103103 }
104104
105- observabilityPolicy := & ngfAPIv1alpha1 .ObservabilityPolicy {
105+ observabilityPolicy := & ngfAPIv1alpha2 .ObservabilityPolicy {
106106 ObjectMeta : controllerruntime.ObjectMeta {
107107 Name : uniqueResourceName (testResourceName ),
108108 Namespace : defaultNamespace ,
@@ -119,13 +119,13 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) {
119119 k8sClient := getKubernetesClient (t )
120120
121121 tests := []struct {
122- spec ngfAPIv1alpha1 .ObservabilityPolicySpec
122+ spec ngfAPIv1alpha2 .ObservabilityPolicySpec
123123 name string
124124 wantErrors []string
125125 }{
126126 {
127127 name : "Validate gateway.networking.k8s.io TargetRef Group is allowed" ,
128- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
128+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
129129 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
130130 {
131131 Kind : httpRouteKind ,
@@ -137,7 +137,7 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) {
137137 {
138138 name : "Validate invalid.networking.k8s.io TargetRef Group is not allowed" ,
139139 wantErrors : []string {expectedTargetRefGroupError },
140- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
140+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
141141 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
142142 {
143143 Kind : httpRouteKind ,
@@ -149,7 +149,7 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) {
149149 {
150150 name : "Validate discovery.k8s.io/v1 TargetRef Group is not allowed" ,
151151 wantErrors : []string {expectedTargetRefGroupError },
152- spec : ngfAPIv1alpha1 .ObservabilityPolicySpec {
152+ spec : ngfAPIv1alpha2 .ObservabilityPolicySpec {
153153 TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
154154 {
155155 Kind : httpRouteKind ,
@@ -169,7 +169,54 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) {
169169 spec .TargetRefs [i ].Name = gatewayv1alpha2 .ObjectName (uniqueResourceName (testTargetRefName ))
170170 }
171171
172- observabilityPolicy := & ngfAPIv1alpha1.ObservabilityPolicy {
172+ observabilityPolicy := & ngfAPIv1alpha2.ObservabilityPolicy {
173+ ObjectMeta : controllerruntime.ObjectMeta {
174+ Name : uniqueResourceName (testResourceName ),
175+ Namespace : defaultNamespace ,
176+ },
177+ Spec : spec ,
178+ }
179+ validateCrd (t , tt .wantErrors , observabilityPolicy , k8sClient )
180+ })
181+ }
182+ }
183+
184+ func TestObservabilityPoliciesTargetRefKindAndNameCombo (t * testing.T ) {
185+ t .Parallel ()
186+ k8sClient := getKubernetesClient (t )
187+
188+ tests := []struct {
189+ spec ngfAPIv1alpha2.ObservabilityPolicySpec
190+ name string
191+ wantErrors []string
192+ }{
193+ {
194+ // This test is not throwing an error like we expect it to...
195+ name : "Validate TargetRef Kind and Name combination is unique" ,
196+ wantErrors : []string {expectedTargetRefKindAndNameComboMustBeUnique },
197+ spec : ngfAPIv1alpha2.ObservabilityPolicySpec {
198+ TargetRefs : []gatewayv1alpha2.LocalPolicyTargetReference {
199+ {
200+ Kind : httpRouteKind ,
201+ Name : gatewayv1alpha2 .ObjectName (testTargetRefName ),
202+ Group : gatewayGroup ,
203+ },
204+ {
205+ Kind : httpRouteKind ,
206+ Name : gatewayv1alpha2 .ObjectName (testTargetRefName ),
207+ Group : gatewayGroup ,
208+ },
209+ },
210+ },
211+ },
212+ }
213+
214+ for _ , tt := range tests {
215+ t .Run (tt .name , func (t * testing.T ) {
216+ t .Parallel ()
217+ spec := tt .spec
218+
219+ observabilityPolicy := & ngfAPIv1alpha2.ObservabilityPolicy {
173220 ObjectMeta : controllerruntime.ObjectMeta {
174221 Name : uniqueResourceName (testResourceName ),
175222 Namespace : defaultNamespace ,
0 commit comments