Commit fbd5597e authored by Jordan Liggitt's avatar Jordan Liggitt

Add system root unit test

parent 921c60d3
...@@ -93,20 +93,32 @@ stR0Yiw0buV6DL/moUO0HIM9Bjh96HJp+LxiIS6UCdIhMPp5HoQa ...@@ -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",
}}, }},
...@@ -267,6 +279,18 @@ func TestNew(t *testing.T) { ...@@ -267,6 +279,18 @@ func TestNew(t *testing.T) {
} }
switch { 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 {
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)
case !testCase.TLSCert && transport.TLSClientConfig.GetClientCertificate != nil: case !testCase.TLSCert && transport.TLSClientConfig.GetClientCertificate != nil:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment