From cf845c96b3f4e0e1379909aa257aef397d61e340 Mon Sep 17 00:00:00 2001 From: Carlisia Thompson Date: Wed, 17 Aug 2022 10:33:12 -0700 Subject: [PATCH] Delete conversion helpers that moved to the converter pkg --- apis/v1alpha2/validation/util/utils.go | 33 ------- apis/v1alpha2/validation/util/utils_test.go | 104 -------------------- apis/v1beta1/validation/util/utils.go | 33 ------- apis/v1beta1/validation/util/utils_test.go | 104 -------------------- 4 files changed, 274 deletions(-) delete mode 100644 apis/v1alpha2/validation/util/utils.go delete mode 100644 apis/v1alpha2/validation/util/utils_test.go delete mode 100644 apis/v1beta1/validation/util/utils.go delete mode 100644 apis/v1beta1/validation/util/utils_test.go diff --git a/apis/v1alpha2/validation/util/utils.go b/apis/v1alpha2/validation/util/utils.go deleted file mode 100644 index 9513bbff27..0000000000 --- a/apis/v1alpha2/validation/util/utils.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package utils - -import ( - gatewayv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" -) - -// PathMatchTypePtr translates a string to *PathMatchType -func PathMatchTypePtr(s string) *gatewayv1a2.PathMatchType { - result := gatewayv1a2.PathMatchType(s) - return &result -} - -// PortNumberPtr translates an int to a *PortNumber -func PortNumberPtr(p int) *gatewayv1a2.PortNumber { - result := gatewayv1a2.PortNumber(p) - return &result -} diff --git a/apis/v1alpha2/validation/util/utils_test.go b/apis/v1alpha2/validation/util/utils_test.go deleted file mode 100644 index c3131343be..0000000000 --- a/apis/v1alpha2/validation/util/utils_test.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package utils - -import ( - "testing" - - gatewayv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" -) - -func Test_PortNumberPtr(t *testing.T) { - var exportedPort65535 gatewayv1a2.PortNumber = 65535 - var exportedPort1 gatewayv1a2.PortNumber = 1 - var exportedPort0 gatewayv1a2.PortNumber - var exportedPort65536 gatewayv1a2.PortNumber = 65536 - - portNumberPtrTests := []struct { - name string - port int - expectedPort *gatewayv1a2.PortNumber - }{ - { - name: "invalid port number", - port: 0, - expectedPort: &exportedPort0, - }, - { - name: "valid port number", - port: 65535, - expectedPort: &exportedPort65535, - }, - { - name: "invalid port number", - port: 65536, - expectedPort: &exportedPort65536, - }, - { - name: "valid port number", - port: 1, - expectedPort: &exportedPort1, - }, - } - - for _, tc := range portNumberPtrTests { - t.Run(tc.name, func(t *testing.T) { - port := PortNumberPtr(tc.port) - if port == nil || tc.expectedPort == nil { - if port != tc.expectedPort { - t.Errorf("Expected port %d, got %d", tc.expectedPort, port) - } - } else if *port != *tc.expectedPort { - t.Errorf("Expected port %d, got %d", *tc.expectedPort, *port) - } - }) - } -} - -func Test_PathMatchTypePtr(t *testing.T) { - pathMatchTypePtrTests := []struct { - name string - pathType string - expectedPath gatewayv1a2.PathMatchType - }{ - { - name: "valid path exact match", - pathType: "Exact", - expectedPath: gatewayv1a2.PathMatchExact, - }, - - { - name: "valid path prefix match", - pathType: "PathPrefix", - expectedPath: gatewayv1a2.PathMatchPathPrefix, - }, - { - name: "valid path regular expression match", - pathType: "RegularExpression", - expectedPath: gatewayv1a2.PathMatchRegularExpression, - }, - } - - for _, tc := range pathMatchTypePtrTests { - t.Run(tc.name, func(t *testing.T) { - path := PathMatchTypePtr(tc.pathType) - if *path != tc.expectedPath { - t.Errorf("Expected path %s, got %s", tc.expectedPath, *path) - } - }) - } -} diff --git a/apis/v1beta1/validation/util/utils.go b/apis/v1beta1/validation/util/utils.go deleted file mode 100644 index 52408574ad..0000000000 --- a/apis/v1beta1/validation/util/utils.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package utils - -import ( - gatewayv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" -) - -// PathMatchTypePtr translates a string to *PathMatchType -func PathMatchTypePtr(s string) *gatewayv1b1.PathMatchType { - result := gatewayv1b1.PathMatchType(s) - return &result -} - -// PortNumberPtr translates an int to a *PortNumber -func PortNumberPtr(p int) *gatewayv1b1.PortNumber { - result := gatewayv1b1.PortNumber(p) - return &result -} diff --git a/apis/v1beta1/validation/util/utils_test.go b/apis/v1beta1/validation/util/utils_test.go deleted file mode 100644 index 9e0deb62da..0000000000 --- a/apis/v1beta1/validation/util/utils_test.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright 2021 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package utils - -import ( - "testing" - - gatewayv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" -) - -func Test_PortNumberPtr(t *testing.T) { - var exportedPort65535 gatewayv1b1.PortNumber = 65535 - var exportedPort1 gatewayv1b1.PortNumber = 1 - var exportedPort0 gatewayv1b1.PortNumber - var exportedPort65536 gatewayv1b1.PortNumber = 65536 - - portNumberPtrTests := []struct { - name string - port int - expectedPort *gatewayv1b1.PortNumber - }{ - { - name: "invalid port number", - port: 0, - expectedPort: &exportedPort0, - }, - { - name: "valid port number", - port: 65535, - expectedPort: &exportedPort65535, - }, - { - name: "invalid port number", - port: 65536, - expectedPort: &exportedPort65536, - }, - { - name: "valid port number", - port: 1, - expectedPort: &exportedPort1, - }, - } - - for _, tc := range portNumberPtrTests { - t.Run(tc.name, func(t *testing.T) { - port := PortNumberPtr(tc.port) - if port == nil || tc.expectedPort == nil { - if port != tc.expectedPort { - t.Errorf("Expected port %d, got %d", tc.expectedPort, port) - } - } else if *port != *tc.expectedPort { - t.Errorf("Expected port %d, got %d", *tc.expectedPort, *port) - } - }) - } -} - -func Test_PathMatchTypePtr(t *testing.T) { - pathMatchTypePtrTests := []struct { - name string - pathType string - expectedPath gatewayv1b1.PathMatchType - }{ - { - name: "valid path exact match", - pathType: "Exact", - expectedPath: gatewayv1b1.PathMatchExact, - }, - - { - name: "valid path prefix match", - pathType: "PathPrefix", - expectedPath: gatewayv1b1.PathMatchPathPrefix, - }, - { - name: "valid path regular expression match", - pathType: "RegularExpression", - expectedPath: gatewayv1b1.PathMatchRegularExpression, - }, - } - - for _, tc := range pathMatchTypePtrTests { - t.Run(tc.name, func(t *testing.T) { - path := PathMatchTypePtr(tc.pathType) - if *path != tc.expectedPath { - t.Errorf("Expected path %s, got %s", tc.expectedPath, *path) - } - }) - } -}