|
| 1 | +/* |
| 2 | +Copyright 2017 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 kubelet |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/http" |
| 21 | + "testing" |
| 22 | +) |
| 23 | + |
| 24 | +func TestNewClient(t *testing.T) { |
| 25 | + testCases := []struct { |
| 26 | + name string |
| 27 | + host string |
| 28 | + port uint |
| 29 | + useAuthPort bool |
| 30 | + expectedURL string |
| 31 | + }{ |
| 32 | + { |
| 33 | + name: "IPv4 HTTP", |
| 34 | + host: "127.0.0.1", |
| 35 | + port: 10255, |
| 36 | + useAuthPort: false, |
| 37 | + expectedURL: "http://127.0.0.1:10255/stats/summary", |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "IPv4 HTTPS", |
| 41 | + host: "127.0.0.1", |
| 42 | + port: 10250, |
| 43 | + useAuthPort: true, |
| 44 | + expectedURL: "https://127.0.0.1:10250/stats/summary", |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "IPv6 HTTP", |
| 48 | + host: "2001:db8::1", |
| 49 | + port: 10255, |
| 50 | + useAuthPort: false, |
| 51 | + expectedURL: "http://[2001:db8::1]:10255/stats/summary", |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "IPv6 HTTPS", |
| 55 | + host: "2001:db8::1", |
| 56 | + port: 10250, |
| 57 | + useAuthPort: true, |
| 58 | + expectedURL: "https://[2001:db8::1]:10250/stats/summary", |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + for _, tc := range testCases { |
| 63 | + t.Run(tc.name, func(t *testing.T) { |
| 64 | + c, err := NewClient(tc.host, tc.port, http.DefaultClient, tc.useAuthPort) |
| 65 | + if err != nil { |
| 66 | + t.Fatalf("NewClient failed: %v", err) |
| 67 | + } |
| 68 | + if c.summaryURL.String() != tc.expectedURL { |
| 69 | + t.Errorf("Expected URL %q, got %q", tc.expectedURL, c.summaryURL.String()) |
| 70 | + } |
| 71 | + }) |
| 72 | + } |
| 73 | +} |
0 commit comments