Add system root unit test

Kubernetes-commit: fbd5597e9914fc24ece3b21e6015748ed865de7b
This commit is contained in:
Jordan Liggitt 2018-10-23 13:48:05 -04:00 committed by Kubernetes Publisher
parent d355f0b411
commit 63eb0a3a1f

View File

@ -93,20 +93,32 @@ stR0Yiw0buV6DL/moUO0HIM9Bjh96HJp+LxiIS6UCdIhMPp5HoQa
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
testCases := map[string]struct { testCases := map[string]struct {
Config *Config Config *Config
Err bool Err bool
TLS bool TLS bool
TLSCert bool TLSCert bool
TLSErr bool TLSErr bool
Default bool Default bool
Insecure bool
DefaultRoots bool
}{ }{
"default transport": { "default transport": {
Default: true, Default: true,
Config: &Config{}, Config: &Config{},
}, },
"insecure": {
TLS: true,
Insecure: true,
DefaultRoots: true,
Config: &Config{TLS: TLSConfig{
Insecure: true,
}},
},
"server name": { "server name": {
TLS: true, TLS: true,
DefaultRoots: true,
Config: &Config{TLS: TLSConfig{ Config: &Config{TLS: TLSConfig{
ServerName: "foo", ServerName: "foo",
}}, }},
@ -266,6 +278,18 @@ func TestNew(t *testing.T) {
return return
} }
switch {
case testCase.DefaultRoots && transport.TLSClientConfig.RootCAs != nil:
t.Fatalf("got %#v, expected nil root CAs", transport.TLSClientConfig.RootCAs)
case !testCase.DefaultRoots && transport.TLSClientConfig.RootCAs == nil:
t.Fatalf("got %#v, expected non-nil root CAs", transport.TLSClientConfig.RootCAs)
}
switch {
case testCase.Insecure != transport.TLSClientConfig.InsecureSkipVerify:
t.Fatalf("got %#v, expected %#v", transport.TLSClientConfig.InsecureSkipVerify, testCase.Insecure)
}
switch { switch {
case testCase.TLSCert && transport.TLSClientConfig.GetClientCertificate == nil: case testCase.TLSCert && transport.TLSClientConfig.GetClientCertificate == nil:
t.Fatalf("got %#v, expected TLSClientConfig.GetClientCertificate", transport.TLSClientConfig) t.Fatalf("got %#v, expected TLSClientConfig.GetClientCertificate", transport.TLSClientConfig)