@@ -22,14 +22,20 @@ func TestClientConfiguration(t *testing.T) {
2222 t .Parallel ()
2323
2424 t .Run ("With empty" , func (t * testing.T ) {
25- _ , err := NewDefaultClient ()
25+ c , err := NewDefaultClient ()
2626
2727 if err != nil {
2828 t .Errorf ("Unexpected error: %s" , err )
2929 }
30+
31+ u := c .Transport .(* estransport.Client ).URLs ()[0 ].String ()
32+
33+ if u != defaultURL {
34+ t .Errorf ("Unexpected URL, want=%s, got=%s" , defaultURL , u )
35+ }
3036 })
3137
32- t .Run ("With address " , func (t * testing.T ) {
38+ t .Run ("With URL from Addresses " , func (t * testing.T ) {
3339 c , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }})
3440 if err != nil {
3541 t .Fatalf ("Unexpected error: %s" , err )
@@ -62,32 +68,36 @@ func TestClientConfiguration(t *testing.T) {
6268 os .Setenv ("ELASTICSEARCH_URL" , "http://example.com" )
6369 defer func () { os .Setenv ("ELASTICSEARCH_URL" , "" ) }()
6470
65- _ , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }})
66- if err = = nil {
67- t .Fatalf ("Expected error, got : %v " , err )
71+ c , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }})
72+ if err ! = nil {
73+ t .Fatalf ("Unexpected error: %s " , err )
6874 }
69- match , _ := regexp .MatchString ("both .* are set" , err .Error ())
70- if ! match {
71- t .Errorf ("Expected error when addresses from environment and configuration are used together, got: %v" , err )
75+
76+ u := c .Transport .(* estransport.Client ).URLs ()[0 ].String ()
77+
78+ if u != "http://localhost:8080" {
79+ t .Errorf ("Unexpected URL, want=http://localhost:8080, got=%s" , u )
7280 }
7381 })
7482
7583 t .Run ("With URL from environment and cfg.CloudID" , func (t * testing.T ) {
7684 os .Setenv ("ELASTICSEARCH_URL" , "http://example.com" )
7785 defer func () { os .Setenv ("ELASTICSEARCH_URL" , "" ) }()
7886
79- _ , err := NewClient (Config {CloudID : "foobar =" })
80- if err = = nil {
81- t .Fatalf ("Expected error, got : %v " , err )
87+ c , err := NewClient (Config {CloudID : "foo:YmFyLmNsb3VkLmVzLmlvJGFiYzEyMyRkZWY0NTY =" })
88+ if err ! = nil {
89+ t .Fatalf ("Unexpected error: %s " , err )
8290 }
83- match , _ := regexp .MatchString ("both .* are set" , err .Error ())
84- if ! match {
85- t .Errorf ("Expected error when addresses from environment and configuration are used together, got: %v" , err )
91+
92+ u := c .Transport .(* estransport.Client ).URLs ()[0 ].String ()
93+
94+ if u != "https://abc123.bar.cloud.es.io" {
95+ t .Errorf ("Unexpected URL, want=https://abc123.bar.cloud.es.io, got=%s" , u )
8696 }
8797 })
8898
8999 t .Run ("With cfg.Addresses and cfg.CloudID" , func (t * testing.T ) {
90- _ , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }, CloudID : "foobar =" })
100+ _ , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }, CloudID : "foo:ABC =" })
91101 if err == nil {
92102 t .Fatalf ("Expected error, got: %v" , err )
93103 }
@@ -111,6 +121,25 @@ func TestClientConfiguration(t *testing.T) {
111121 }
112122 })
113123
124+ t .Run ("With invalid CloudID" , func (t * testing.T ) {
125+ var err error
126+
127+ _ , err = NewClient (Config {CloudID : "foo:ZZZ===" })
128+ if err == nil {
129+ t .Errorf ("Expected error for CloudID, got: %v" , err )
130+ }
131+
132+ _ , err = NewClient (Config {CloudID : "foo:Zm9v" })
133+ if err == nil {
134+ t .Errorf ("Expected error for CloudID, got: %v" , err )
135+ }
136+
137+ _ , err = NewClient (Config {CloudID : "foo:" })
138+ if err == nil {
139+ t .Errorf ("Expected error for CloudID, got: %v" , err )
140+ }
141+ })
142+
114143 t .Run ("With invalid URL" , func (t * testing.T ) {
115144 u := ":foo"
116145 _ , err := NewClient (Config {Addresses : []string {u }})
0 commit comments