@@ -27,12 +27,6 @@ import (
2727 "encoding/json"
2828 "errors"
2929 "fmt"
30- "github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
31- "github.com/elastic/go-elasticsearch/v8/typedapi/some"
32- "github.com/elastic/go-elasticsearch/v8/typedapi/types"
33- "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
34- "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/result"
35- "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
3630 "log"
3731 "net"
3832 "net/http"
@@ -47,11 +41,40 @@ import (
4741 "github.com/elastic/elastic-transport-go/v8/elastictransport"
4842 "github.com/elastic/go-elasticsearch/v8"
4943 "github.com/elastic/go-elasticsearch/v8/esapi"
44+ "github.com/elastic/go-elasticsearch/v8/internal/containertest"
45+ "github.com/elastic/go-elasticsearch/v8/internal/version"
46+ "github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
47+ "github.com/elastic/go-elasticsearch/v8/typedapi/some"
48+ "github.com/elastic/go-elasticsearch/v8/typedapi/types"
49+ "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
50+ "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/result"
51+ "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
5052)
5153
5254func TestClientTransport (t * testing.T ) {
55+ stackVersion := version .Client
56+ if v := os .Getenv ("STACK_VERSION" ); v != "" {
57+ stackVersion = v
58+ }
59+
60+ elasticsearchSrv , err := containertest .NewElasticsearchService (stackVersion )
61+ if err != nil {
62+ t .Fatalf ("Error setting up Elasticsearch container: %s" , err )
63+ }
64+ defer func () {
65+ if err := elasticsearchSrv .Terminate (context .Background ()); err != nil {
66+ t .Fatalf ("Error terminating Elasticsearch container: %s" , err )
67+ }
68+ }()
69+
70+ tcCfg := elasticsearchSrv .ESConfig ()
71+
72+ t .Setenv ("ELASTICSEARCH_URL" , tcCfg .Addresses [0 ])
73+ t .Setenv ("ELASTICSEARCH_USERNAME" , tcCfg .Username )
74+ t .Setenv ("ELASTICSEARCH_PASSWORD" , tcCfg .Password )
75+
5376 t .Run ("Persistent" , func (t * testing.T ) {
54- es , err := elasticsearch .NewDefaultClient ( )
77+ es , err := elasticsearch .NewClient ( tcCfg )
5578 if err != nil {
5679 t .Fatalf ("Error creating the client: %s" , err )
5780 }
@@ -103,7 +126,7 @@ func TestClientTransport(t *testing.T) {
103126 t .Run ("Concurrent" , func (t * testing.T ) {
104127 var wg sync.WaitGroup
105128
106- es , err := elasticsearch .NewDefaultClient ( )
129+ es , err := elasticsearch .NewClient ( tcCfg )
107130 if err != nil {
108131 t .Fatalf ("Error creating the client: %s" , err )
109132 }
@@ -126,7 +149,7 @@ func TestClientTransport(t *testing.T) {
126149 })
127150
128151 t .Run ("WithContext" , func (t * testing.T ) {
129- es , err := elasticsearch .NewDefaultClient ( )
152+ es , err := elasticsearch .NewClient ( tcCfg )
130153 if err != nil {
131154 t .Fatalf ("Error creating the client: %s" , err )
132155 }
@@ -154,6 +177,12 @@ func TestClientTransport(t *testing.T) {
154177 InsecureSkipVerify : true ,
155178 },
156179 },
180+ Addresses : []string {
181+ tcCfg .Addresses [0 ],
182+ },
183+ Username : tcCfg .Username ,
184+ Password : tcCfg .Password ,
185+ CACert : tcCfg .CACert ,
157186 }
158187
159188 es , err := elasticsearch .NewClient (cfg )
0 commit comments