@@ -96,3 +96,53 @@ func TestCreateElasticSearchServiceForDefaultClusterName(t *testing.T) {
9696 t .Fatalf ("cluster name is not equal. Expected: %s, Got: %s" , ESClusterName , esSvc .ClusterName )
9797 }
9898}
99+
100+ func TestCreateElasticSearchServiceSingleDnsEntrypoint (t * testing.T ) {
101+ clusterName := "sandbox"
102+ esURI := fmt .Sprintf ("https://foo.com:9200?" +
103+ "esUserName=test&esUserSecret=password&maxRetries=10&startupHealthcheckTimeout=30&" +
104+ "sniff=false&healthCheck=false&cluster_name=%s" , clusterName )
105+
106+ url , err := url .Parse (esURI )
107+ if err != nil {
108+ t .Fatalf ("Error when parsing URL: %s" , err .Error ())
109+ }
110+
111+ esSvc , err := CreateElasticSearchService (url )
112+ if err != nil {
113+ t .Fatalf ("Error when creating config: %s" , err .Error ())
114+ }
115+
116+ expectedClient , err := elastic .NewClient (
117+ elastic .SetURL ("https://foo.com:9200" ),
118+ elastic .SetBasicAuth ("test" , "password" ),
119+ elastic .SetMaxRetries (10 ),
120+ elastic .SetHealthcheckTimeoutStartup (30 * time .Second ),
121+ elastic .SetSniff (false ), elastic .SetHealthcheck (false ))
122+
123+ if err != nil {
124+ t .Fatalf ("Error when creating client: %s" , err .Error ())
125+ }
126+
127+ actualClientRefl := reflect .ValueOf (esSvc .EsClient ).Elem ()
128+ expectedClientRefl := reflect .ValueOf (expectedClient ).Elem ()
129+
130+ if actualClientRefl .FieldByName ("basicAuthUsername" ).String () != expectedClientRefl .FieldByName ("basicAuthUsername" ).String () {
131+ t .Fatal ("basicAuthUsername is not equal" )
132+ }
133+ if actualClientRefl .FieldByName ("maxRetries" ).Int () != expectedClientRefl .FieldByName ("maxRetries" ).Int () {
134+ t .Fatal ("maxRetries is not equal" )
135+ }
136+ if actualClientRefl .FieldByName ("healthcheckTimeoutStartup" ).Int () != expectedClientRefl .FieldByName ("healthcheckTimeoutStartup" ).Int () {
137+ t .Fatal ("healthcheckTimeoutStartup is not equal" )
138+ }
139+ if actualClientRefl .FieldByName ("snifferEnabled" ).Bool () != expectedClientRefl .FieldByName ("snifferEnabled" ).Bool () {
140+ t .Fatal ("snifferEnabled is not equal" )
141+ }
142+ if actualClientRefl .FieldByName ("healthcheckEnabled" ).Bool () != expectedClientRefl .FieldByName ("healthcheckEnabled" ).Bool () {
143+ t .Fatal ("healthcheckEnabled is not equal" )
144+ }
145+ if esSvc .ClusterName != clusterName {
146+ t .Fatal ("cluster name is not equal" )
147+ }
148+ }
0 commit comments