@@ -103,7 +103,10 @@ func TestWithMockedServer(t *testing.T) {
103
103
test .GomegaSubTest (SubTestWithNoInfoSD (& di ), "TestWithNoInfoSD" ),
104
104
test .GomegaSubTest (SubTestWithSDNoResponseContent (& di ), "TestWithSDNoResponseContent" ),
105
105
test .GomegaSubTest (SubTestWithBaseURL (& di ), "TestWithBaseURL" ),
106
+ test .GomegaSubTest (SubTestWithBaseURLFailure (& di ), "TestWithBaseUrlFailure" ),
107
+ test .GomegaSubTest (SubTestWithSDFailure (& di ), "TestWithSDFailure" ),
106
108
test .GomegaSubTest (SubTestWithErrorResponse (& di ), "TestWithErrorResponse" ),
109
+ test .GomegaSubTest (SubTestWithUnexpectedStatusCodeInErrorResponse (& di ), "TestWithUnexpectedStatusCodeInErrorResponse" ),
107
110
test .GomegaSubTest (SubTestWithNoContentErrorResponse (& di ), "SubTestWithNoContentErrorResponse" ),
108
111
test .GomegaSubTest (SubTestWithFailedSD (& di ), "TestWithFailedSD" ),
109
112
test .GomegaSubTest (SubTestWithRetry (& di ), "TestWithRetry" ),
@@ -164,7 +167,7 @@ func SubTestWithNoInfoSD(di *TestDI) test.GomegaSubTestFunc {
164
167
if len (target .Port ()) != 0 {
165
168
return nil , fmt .Errorf ("target URL [%s] should not have port" , target .String ())
166
169
}
167
- target .Host = fmt .Sprintf (`%s:%d` ,target .Host , webtest .CurrentPort (ctx ))
170
+ target .Host = fmt .Sprintf (`%s:%d` , target .Host , webtest .CurrentPort (ctx ))
168
171
return http .NewRequestWithContext (ctx , method , target .String (), nil )
169
172
}
170
173
performEchoTest (ctx , t , g , client , httpclient .WithRequestCreator (urlRewriteCreator ))
@@ -179,6 +182,16 @@ func SubTestWithSDNoResponseContent(di *TestDI) test.GomegaSubTestFunc {
179
182
}
180
183
}
181
184
185
+ func SubTestWithSDFailure (di * TestDI ) test.GomegaSubTestFunc {
186
+ return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
187
+ _ , e := di .HttpClient .WithService ("" )
188
+ //checking the error type, ignoring the error message
189
+ g .Expect (e ).To (MatchError (httpclient .NewNoEndpointFoundError ("error message doesn't matter" )))
190
+ //check that the message is formatted
191
+ g .Expect (e ).To (MatchError (Not (ContainSubstring ("%" ))))
192
+ }
193
+ }
194
+
182
195
func SubTestWithBaseURL (di * TestDI ) test.GomegaSubTestFunc {
183
196
return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
184
197
baseUrl := fmt .Sprintf (`http://localhost:%d%s` , webtest .CurrentPort (ctx ), webtest .CurrentContextPath (ctx ))
@@ -188,6 +201,18 @@ func SubTestWithBaseURL(di *TestDI) test.GomegaSubTestFunc {
188
201
}
189
202
}
190
203
204
+ func SubTestWithBaseURLFailure (di * TestDI ) test.GomegaSubTestFunc {
205
+ return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
206
+ baseUrl := webtest .CurrentContextPath (ctx )
207
+ _ , e := di .HttpClient .WithBaseUrl (baseUrl )
208
+ //checking the error type, ignoring the error message
209
+ g .Expect (e ).To (MatchError (httpclient .NewNoEndpointFoundError ("error message doesn't matter" )))
210
+ //check that the message is formatted
211
+ g .Expect (e ).To (MatchError (Not (ContainSubstring ("%" ))))
212
+ g .Expect (e ).To (MatchError (ContainSubstring (baseUrl )))
213
+ }
214
+ }
215
+
191
216
func SubTestWithErrorResponse (di * TestDI ) test.GomegaSubTestFunc {
192
217
return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
193
218
client , e := di .HttpClient .WithService (SDServiceNameFullInfo )
@@ -205,6 +230,26 @@ func SubTestWithErrorResponse(di *TestDI) test.GomegaSubTestFunc {
205
230
}
206
231
}
207
232
233
+ func SubTestWithUnexpectedStatusCodeInErrorResponse (di * TestDI ) test.GomegaSubTestFunc {
234
+ return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
235
+ client , e := di .HttpClient .WithService (SDServiceNameFullInfo )
236
+ g .Expect (e ).To (Succeed (), "client with service name should be available" )
237
+
238
+ sc := 300 + utils .RandomIntN (10 )
239
+ reqBody := makeEchoRequestBody ()
240
+ req := httpclient .NewRequest (TestErrorPath , http .MethodPut ,
241
+ httpclient .WithParam ("sc" , fmt .Sprintf ("%d" , sc )),
242
+ httpclient .WithBody (reqBody ),
243
+ )
244
+
245
+ _ , err := client .Execute (ctx , req , httpclient .JsonBody (& EchoResponse {}))
246
+ // check the error type is the expected type
247
+ g .Expect (err ).To (MatchError (httpclient .ErrorSubTypeInternalError ))
248
+ // check the error message is formatted
249
+ g .Expect (err ).To (MatchError (Not (ContainSubstring ("%" ))))
250
+ }
251
+ }
252
+
208
253
func SubTestWithNoContentErrorResponse (di * TestDI ) test.GomegaSubTestFunc {
209
254
return func (ctx context.Context , t * testing.T , g * gomega.WithT ) {
210
255
client , e := di .HttpClient .WithService (SDServiceNameFullInfo )
0 commit comments