|
| 1 | +/* |
| 2 | +Copyright 2026 Google Inc. |
| 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 util |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | +) |
| 22 | + |
| 23 | +func TestNormalizeHost(t *testing.T) { |
| 24 | + testCases := []struct { |
| 25 | + desc string |
| 26 | + input string |
| 27 | + expected string |
| 28 | + }{ |
| 29 | + { |
| 30 | + desc: "IPv4", |
| 31 | + input: "127.0.0.1", |
| 32 | + expected: "127.0.0.1", |
| 33 | + }, |
| 34 | + { |
| 35 | + desc: "hostname", |
| 36 | + input: "localhost", |
| 37 | + expected: "localhost", |
| 38 | + }, |
| 39 | + { |
| 40 | + desc: "raw IPv6", |
| 41 | + input: "2001:db8::1", |
| 42 | + expected: "2001:db8::1", |
| 43 | + }, |
| 44 | + { |
| 45 | + desc: "bracketed IPv6", |
| 46 | + input: "[2001:db8::1]", |
| 47 | + expected: "2001:db8::1", |
| 48 | + }, |
| 49 | + { |
| 50 | + desc: "bracketed IPv6 with spaces", |
| 51 | + input: " [2001:db8::1] ", |
| 52 | + expected: "2001:db8::1", |
| 53 | + }, |
| 54 | + } |
| 55 | + |
| 56 | + for _, tc := range testCases { |
| 57 | + if got := NormalizeHost(tc.input); got != tc.expected { |
| 58 | + t.Errorf("%s: NormalizeHost(%q) = %q, want %q", tc.desc, tc.input, got, tc.expected) |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments