Skip to content

Commit 6ae9e40

Browse files
committed
Make parrot route setting more flexible
1 parent 49f348d commit 6ae9e40

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/client/mockserver.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ import (
1515
)
1616

1717
// MockserverClient mockserver client
18+
//
1819
// Deprecated: Use Parrot instead
1920
type MockserverClient struct {
2021
APIClient *resty.Client
2122
Config *MockserverConfig
2223
}
2324

2425
// MockserverConfig holds config information for MockserverClient
26+
//
27+
// Deprecated: Use Parrot instead
2528
type MockserverConfig struct {
2629
LocalURL string
2730
ClusterURL string
2831
Headers map[string]string
2932
}
3033

3134
// ConnectMockServer creates a connection to a deployed mockserver in the environment
35+
//
3236
// Deprecated: Use Parrot instead
3337
func ConnectMockServer(e *environment.Environment) *MockserverClient {
3438
c := NewMockserverClient(&MockserverConfig{
@@ -39,6 +43,7 @@ func ConnectMockServer(e *environment.Environment) *MockserverClient {
3943
}
4044

4145
// ConnectMockServerURL creates a connection to a mockserver at a given url, should only be used for inside K8s tests
46+
//
4247
// Deprecated: Use Parrot instead
4348
func ConnectMockServerURL(url string) *MockserverClient {
4449
c := NewMockserverClient(&MockserverConfig{
@@ -49,6 +54,7 @@ func ConnectMockServerURL(url string) *MockserverClient {
4954
}
5055

5156
// NewMockserverClient returns a mockserver client
57+
//
5258
// Deprecated: Use Parrot instead
5359
func NewMockserverClient(cfg *MockserverConfig) *MockserverClient {
5460
log.Debug().Str("Local URL", cfg.LocalURL).Str("Remote URL", cfg.ClusterURL).Msg("Connected to MockServer")
@@ -217,39 +223,53 @@ func (em *MockserverClient) SetStringValuePath(path string, stringValue string)
217223
}
218224

219225
// LocalURL returns the local url of the mockserver
226+
//
227+
// Deprecated: Use Parrot instead
220228
func (em *MockserverClient) LocalURL() string {
221229
return em.Config.LocalURL
222230
}
223231

224232
// PathSelector represents the json object used to find expectations by path
233+
//
234+
// Deprecated: Use Parrot instead
225235
type PathSelector struct {
226236
Path string `json:"path"`
227237
}
228238

229239
// HttpRequest represents the httpRequest json object used in the mockserver initializer
240+
//
241+
// Deprecated: Use Parrot instead
230242
type HttpRequest struct {
231243
Path string `json:"path"`
232244
}
233245

234246
// HttpResponse represents the httpResponse json object used in the mockserver initializer
247+
//
248+
// Deprecated: Use Parrot instead
235249
type HttpResponse struct {
236250
Body interface{} `json:"body"`
237251
}
238252

239253
// HttpInitializer represents an element of the initializer array used in the mockserver initializer
254+
//
255+
// Deprecated: Use Parrot instead
240256
type HttpInitializer struct {
241257
Id string `json:"id"`
242258
Request HttpRequest `json:"httpRequest"`
243259
Response HttpResponse `json:"httpResponse"`
244260
}
245261

246262
// HttpResponse represents the httpResponse json object used in the mockserver initializer
263+
//
264+
// Deprecated: Use Parrot instead
247265
type HttpResponseTemplate struct {
248266
Template string `json:"template"`
249267
TemplateType string `json:"templateType"`
250268
}
251269

252270
// HttpInitializer represents an element of the initializer array used in the mockserver initializer
271+
//
272+
// Deprecated: Use Parrot instead
253273
type HttpInitializerTemplate struct {
254274
Id string `json:"id"`
255275
Request HttpRequest `json:"httpRequest"`
@@ -259,12 +279,16 @@ type HttpInitializerTemplate struct {
259279
// For OTPE - weiwatchers
260280

261281
// NodeInfoJSON represents an element of the nodes array used to deliver configs to otpe
282+
//
283+
// Deprecated: Use Parrot instead
262284
type NodeInfoJSON struct {
263285
ID string `json:"id"`
264286
NodeAddress []string `json:"nodeAddress"`
265287
}
266288

267289
// ContractInfoJSON represents an element of the contracts array used to deliver configs to otpe
290+
//
291+
// Deprecated: Use Parrot instead
268292
type ContractInfoJSON struct {
269293
ContractAddress string `json:"contractAddress"`
270294
ContractVersion int `json:"contractVersion"`
@@ -275,11 +299,15 @@ type ContractInfoJSON struct {
275299
// For Adapter endpoints
276300

277301
// AdapterResult represents an int result for an adapter
302+
//
303+
// Deprecated: Use Parrot instead
278304
type AdapterResult struct {
279305
Result interface{} `json:"result"`
280306
}
281307

282308
// AdapterResponse represents a response from an adapter
309+
//
310+
// Deprecated: Use Parrot instead
283311
type AdapterResponse struct {
284312
Id string `json:"id"`
285313
Data AdapterResult `json:"data"`

lib/docker/test_env/parrot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func (p *Parrot) getContainerRequest() (tc.ContainerRequest, error) {
149149
}
150150

151151
// SetAdapterRoute sets a new route for the mock external adapter, wrapping the provided response in a standard adapter response.
152+
// If you don't want to wrap the response, use Client.RegisterRoute directly.
152153
func (p *Parrot) SetAdapterRoute(route *parrot.Route) error {
153154
var result any
154155
if route.RawResponseBody != "" {

parrot/parrot.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ func (p *Server) Register(route *Route) error {
335335
if route == nil {
336336
return ErrNilRoute
337337
}
338+
if !strings.HasPrefix(route.Path, "/") {
339+
route.Path = "/" + route.Path
340+
}
338341
if !isValidPath(route.Path) {
339342
return newDynamicError(ErrInvalidPath, fmt.Sprintf("'%s'", route.Path))
340343
}

0 commit comments

Comments
 (0)