@@ -12,6 +12,7 @@ import (
1212 "reflect"
1313 "strings"
1414 "testing"
15+ "time"
1516
1617 "github.com/google/go-cmp/cmp"
1718 "github.com/jarcoal/httpmock"
@@ -584,22 +585,34 @@ func TestClient_CustomRootCAWithoutCustomRoundTripper(t *testing.T) {
584585 }
585586 defer os .Remove (caFile .Name ())
586587
587- for _ , setCA := range []bool {false , true } {
588- if setCA {
589- t .Setenv (APIHostCert , caFile .Name ())
590- }
591-
592- client := NewClient (nil )
593-
594- transport , err := client .resty .Transport ()
595- if err != nil {
596- t .Fatal (err )
597- }
598- if setCA && (transport .TLSClientConfig == nil || transport .TLSClientConfig .RootCAs == nil ) {
599- t .Error ("expected root CAs to be set" )
600- }
601- if ! setCA && transport .TLSClientConfig != nil {
602- t .Errorf ("didn't set a custom CA, but client TLS config is not nil: %#v" , transport .TLSClientConfig )
603- }
588+ tests := []struct {
589+ name string
590+ setCA bool
591+ httpClient * http.Client
592+ }{
593+ {"do not set CA" , false , nil },
594+ {"set CA" , true , nil },
595+ {"do not set CA, use timeout" , false , & http.Client {Timeout : time .Second }},
596+ {"set CA, use timeout" , true , & http.Client {Timeout : time .Second }},
597+ }
598+
599+ for _ , test := range tests {
600+ t .Run (test .name , func (t * testing.T ) {
601+ if test .setCA {
602+ t .Setenv (APIHostCert , caFile .Name ())
603+ }
604+
605+ client := NewClient (test .httpClient )
606+ transport , err := client .resty .Transport ()
607+ if err != nil {
608+ t .Fatal (err )
609+ }
610+ if test .setCA && (transport .TLSClientConfig == nil || transport .TLSClientConfig .RootCAs == nil ) {
611+ t .Error ("expected root CAs to be set" )
612+ }
613+ if ! test .setCA && transport .TLSClientConfig != nil {
614+ t .Errorf ("didn't set a custom CA, but client TLS config is not nil: %#v" , transport .TLSClientConfig )
615+ }
616+ })
604617 }
605618}
0 commit comments