| 1 | /* |
| 2 | Copyright 2020 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package utilscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/ |
| 18 | |
| 19 | import ( |
| 20 | "testingscip-go gomod github.com/golang/go/src go1.23.6 testing/" |
| 21 | ) |
| 22 | |
| 23 | const ( |
| 24 | failedscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/failed. = "\u2717" |
| 25 | succeedscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/succeed. = "\u2713" |
| 26 | ) |
| 27 | |
| 28 | func TestRemovePortFromHostscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/TestRemovePortFromHost().(t *testingscip-go gomod github.com/golang/go/src go1.23.6 testing/.Tscip-go gomod github.com/golang/go/src go1.23.6 testing/T#) { |
| 29 | tests := []struct { |
| 30 | name string |
| 31 | origHost string |
| 32 | expect string |
| 33 | }{ |
| 34 | {"Domain&Port", "localhost:8080", "localhost"}, |
| 35 | {"Domain", "localhost", "localhost"}, |
| 36 | {"IPv4&Port", "192.168.0.1:8080", "192.168.0.1"}, |
| 37 | {"ShortestIPv6", "::", "::"}, |
| 38 | {"IPv6", "9878::7675:1292:9183:7562", "9878::7675:1292:9183:7562"}, |
| 39 | {"IPv6&Port", "[alsk:1204:1020::1292]:8080", "alsk:1204:1020::1292"}, |
| 40 | {"FQDN", " www.kubernetes.test:8080", " www.kubernetes.test"}, |
| 41 | } |
| 42 | |
| 43 | for _, tt := range tests { |
| 44 | st := tt |
| 45 | tf := func(t *testingscip-go gomod github.com/golang/go/src go1.23.6 testing/.Tscip-go gomod github.com/golang/go/src go1.23.6 testing/T#) { |
| 46 | t.Parallelscip-go gomod github.com/golang/go/src go1.23.6 testing/T#Parallel().() |
| 47 | t.Logfscip-go gomod github.com/golang/go/src go1.23.6 testing/common#Logf().("\tTestCase: %s", st.name) |
| 48 | { |
| 49 | get := RemovePortFromHostscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/RemovePortFromHost().(st.origHost) |
| 50 | if get != st.expect { |
| 51 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.6 testing/common#Fatalf().("\t%s\texpect %v, but get %v", failedscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/failed., st.expect, get) |
| 52 | } |
| 53 | t.Logfscip-go gomod github.com/golang/go/src go1.23.6 testing/common#Logf().("\t%s\texpect %v, get %v", succeedscip-go gomod sigs.k8s.io/apiserver-network-proxy . `sigs.k8s.io/apiserver-network-proxy/pkg/util`/succeed., st.expect, get) |
| 54 | |
| 55 | } |
| 56 | } |
| 57 | t.Runscip-go gomod github.com/golang/go/src go1.23.6 testing/T#Run().(st.name, tf) |
| 58 | } |
| 59 | } |