@@ -28,6 +28,71 @@ import (
2828 stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
2929)
3030
31+ func TestNewClient (t * testing.T ) {
32+ testCases := []struct {
33+ name string
34+ host string
35+ port uint
36+ useAuthPort bool
37+ expectedURL string
38+ }{
39+ {
40+ name : "IPv4 HTTP" ,
41+ host : "127.0.0.1" ,
42+ port : 10255 ,
43+ useAuthPort : false ,
44+ expectedURL : "http://127.0.0.1:10255/stats/summary" ,
45+ },
46+ {
47+ name : "IPv4 HTTPS" ,
48+ host : "127.0.0.1" ,
49+ port : 10250 ,
50+ useAuthPort : true ,
51+ expectedURL : "https://127.0.0.1:10250/stats/summary" ,
52+ },
53+ {
54+ name : "IPv6 HTTP" ,
55+ host : "2001:db8::1" ,
56+ port : 10255 ,
57+ useAuthPort : false ,
58+ expectedURL : "http://[2001:db8::1]:10255/stats/summary" ,
59+ },
60+ {
61+ name : "IPv6 HTTPS" ,
62+ host : "2001:db8::1" ,
63+ port : 10250 ,
64+ useAuthPort : true ,
65+ expectedURL : "https://[2001:db8::1]:10250/stats/summary" ,
66+ },
67+ {
68+ name : "Bracketed IPv6 HTTP" ,
69+ host : "[2001:db8::1]" ,
70+ port : 10255 ,
71+ useAuthPort : false ,
72+ expectedURL : "http://[2001:db8::1]:10255/stats/summary" ,
73+ },
74+ {
75+ name : "Bracketed IPv6 HTTPS" ,
76+ host : "[2001:db8::1]" ,
77+ port : 10250 ,
78+ useAuthPort : true ,
79+ expectedURL : "https://[2001:db8::1]:10250/stats/summary" ,
80+ },
81+ }
82+
83+ for _ , tc := range testCases {
84+ t .Run (tc .name , func (t * testing.T ) {
85+ c , err := NewClient (tc .host , tc .port , http .DefaultClient , tc .useAuthPort )
86+ if err != nil {
87+ t .Fatalf ("NewClient failed: %v" , err )
88+ }
89+ if c .summaryURL .String () != tc .expectedURL {
90+ t .Errorf ("Expected URL %q, got %q" , tc .expectedURL , c .summaryURL .String ())
91+ }
92+ })
93+ }
94+ }
95+
3196func TestDoRequestAndUnmarshal_SizeLimit (t * testing.T ) {
3297 largeDataSize := maxResponseBodySize + 1024
3398 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
0 commit comments