@@ -22,14 +22,20 @@ func TestClientConfiguration(t *testing.T) {
22
22
t .Parallel ()
23
23
24
24
t .Run ("With empty" , func (t * testing.T ) {
25
- _ , err := NewDefaultClient ()
25
+ c , err := NewDefaultClient ()
26
26
27
27
if err != nil {
28
28
t .Errorf ("Unexpected error: %s" , err )
29
29
}
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
+ }
30
36
})
31
37
32
- t .Run ("With address " , func (t * testing.T ) {
38
+ t .Run ("With URL from Addresses " , func (t * testing.T ) {
33
39
c , err := NewClient (Config {Addresses : []string {"http://localhost:8080//" }})
34
40
if err != nil {
35
41
t .Fatalf ("Unexpected error: %s" , err )
@@ -62,32 +68,36 @@ func TestClientConfiguration(t *testing.T) {
62
68
os .Setenv ("ELASTICSEARCH_URL" , "http://example.com" )
63
69
defer func () { os .Setenv ("ELASTICSEARCH_URL" , "" ) }()
64
70
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 )
68
74
}
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 )
72
80
}
73
81
})
74
82
75
83
t .Run ("With URL from environment and cfg.CloudID" , func (t * testing.T ) {
76
84
os .Setenv ("ELASTICSEARCH_URL" , "http://example.com" )
77
85
defer func () { os .Setenv ("ELASTICSEARCH_URL" , "" ) }()
78
86
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 )
82
90
}
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 )
86
96
}
87
97
})
88
98
89
99
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 =" })
91
101
if err == nil {
92
102
t .Fatalf ("Expected error, got: %v" , err )
93
103
}
@@ -111,6 +121,25 @@ func TestClientConfiguration(t *testing.T) {
111
121
}
112
122
})
113
123
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
+
114
143
t .Run ("With invalid URL" , func (t * testing.T ) {
115
144
u := ":foo"
116
145
_ , err := NewClient (Config {Addresses : []string {u }})
0 commit comments