77 "testing"
88)
99
10+ const testEndpoint = "https://test.endpoint"
11+
1012func TestNewConfigurationFromOptions (t * testing.T ) {
1113 tests := []struct {
1214 name string
@@ -16,9 +18,9 @@ func TestNewConfigurationFromOptions(t *testing.T) {
1618 {
1719 name : "ValidOptions" ,
1820 clientOptions : ClientOptions {
19- Endpoint : "https://test.endpoint" ,
21+ Endpoint : testEndpoint ,
2022 SkipTLSVerify : true ,
21- Certificate : "testCertData " ,
23+ Certificate : "" ,
2224 Credentials : Credentials {
2325 Username : "testUser" ,
2426 Password : "testPass" ,
@@ -31,7 +33,7 @@ func TestNewConfigurationFromOptions(t *testing.T) {
3133 Token : "testToken" ,
3234 Servers : ServerConfigurations {
3335 {
34- URL : "https://test.endpoint" ,
36+ URL : testEndpoint ,
3537 Description : "Production" ,
3638 },
3739 },
@@ -46,7 +48,7 @@ func TestNewConfigurationFromOptions(t *testing.T) {
4648 name : "EmptyEndpoint" ,
4749 clientOptions : ClientOptions {
4850 SkipTLSVerify : true ,
49- Certificate : "testCertData " ,
51+ Certificate : "" ,
5052 Credentials : Credentials {
5153 Username : "testUser" ,
5254 Password : "testPass" ,
@@ -68,17 +70,17 @@ func TestNewConfigurationFromOptions(t *testing.T) {
6870 {
6971 name : "NoCredentials" ,
7072 clientOptions : ClientOptions {
71- Endpoint : "https://test.endpoint" ,
73+ Endpoint : testEndpoint ,
7274 SkipTLSVerify : true ,
73- Certificate : "testCertData " ,
75+ Certificate : "" ,
7476 },
7577 expectedConfig : & Configuration {
7678 Username : "" ,
7779 Password : "" ,
7880 Token : "" ,
7981 Servers : ServerConfigurations {
8082 {
81- URL : "https://test.endpoint" ,
83+ URL : testEndpoint ,
8284 Description : "Production" ,
8385 },
8486 },
@@ -92,8 +94,8 @@ func TestNewConfigurationFromOptions(t *testing.T) {
9294 {
9395 name : "AddCertificate" ,
9496 clientOptions : ClientOptions {
95- Endpoint : "https://test.endpoint" ,
96- SkipTLSVerify : false ,
97+ Endpoint : testEndpoint ,
98+ SkipTLSVerify : true ,
9799 Certificate : "testCertData" ,
98100 Credentials : Credentials {
99101 Username : "testUser" ,
@@ -107,13 +109,16 @@ func TestNewConfigurationFromOptions(t *testing.T) {
107109 Token : "testToken" ,
108110 Servers : ServerConfigurations {
109111 {
110- URL : "https://test.endpoint" ,
112+ URL : testEndpoint ,
111113 Description : "Production" ,
112114 },
113115 },
114116 HTTPClient : & http.Client {
115117 Transport : & http.Transport {
116- TLSClientConfig : & tls.Config {},
118+ TLSClientConfig : & tls.Config {
119+ InsecureSkipVerify : true ,
120+ RootCAs : AddCertsToClient ("testCertData" ),
121+ },
117122 },
118123 },
119124 },
@@ -128,9 +133,9 @@ func TestNewConfigurationFromOptions(t *testing.T) {
128133 assert .Equal (t , tt .expectedConfig .Token , config .Token )
129134 assert .Equal (t , tt .expectedConfig .Servers , config .Servers )
130135 assert .NotNil (t , config .HTTPClient )
131- if tt .clientOptions . SkipTLSVerify {
132- assert . True ( t , config .HTTPClient .Transport .(* http.Transport ).TLSClientConfig .InsecureSkipVerify )
133- }
136+ assert . Equal ( t , tt .expectedConfig . HTTPClient . Transport .( * http. Transport ). TLSClientConfig . InsecureSkipVerify ,
137+ config .HTTPClient .Transport .(* http.Transport ).TLSClientConfig .InsecureSkipVerify )
138+ assert . True ( t , config . HTTPClient . Transport .( * http. Transport ). TLSClientConfig . RootCAs . Equal ( tt . expectedConfig . HTTPClient . Transport .( * http. Transport ). TLSClientConfig . RootCAs ))
134139 })
135140 }
136141}
0 commit comments