Skip to content

Commit 49f348d

Browse files
committed
Adds Parrot EA method
1 parent 5f2df4f commit 49f348d

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

lib/docker/test_env/killgrave.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type KillgraveRequest struct {
5757
}
5858

5959
// Response represent the structure of real response
60+
//
61+
// Deprecated: Use Parrot instead
6062
type KillgraveResponse struct {
6163
Status int `json:"status"`
6264
Body string `json:"body,omitempty"`
@@ -66,19 +68,25 @@ type KillgraveResponse struct {
6668
}
6769

6870
// ResponseDelay represent time delay before server responds.
71+
//
72+
// Deprecated: Use Parrot instead
6973
type KillgraveResponseDelay struct {
7074
Delay int64 `json:"delay,omitempty"`
7175
Offset int64 `json:"offset,omitempty"`
7276
}
7377

7478
// AdapterResponse represents a response from an adapter
79+
//
80+
// Deprecated: Use Parrot instead
7581
type KillgraveAdapterResponse struct {
7682
Id string `json:"id"`
7783
Data KillgraveAdapterResult `json:"data"`
7884
Error interface{} `json:"error"`
7985
}
8086

8187
// AdapterResult represents an int result for an adapter
88+
//
89+
// Deprecated: Use Parrot instead
8290
type KillgraveAdapterResult struct {
8391
Result interface{} `json:"result"`
8492
}
@@ -108,8 +116,6 @@ func NewKillgrave(networks []string, impostersDirectoryPath string, opts ...EnvC
108116

109117
// WithTestInstance sets up a Killgrave instance for testing by assigning a test logger and the testing context.
110118
// This allows for better logging during tests and facilitates easier debugging.
111-
//
112-
// Deprecated: Use Parrot instead
113119
func (k *Killgrave) WithTestInstance(t *testing.T) *Killgrave {
114120
k.l = logging.GetTestLogger(t)
115121
k.t = t
@@ -118,8 +124,6 @@ func (k *Killgrave) WithTestInstance(t *testing.T) *Killgrave {
118124

119125
// StartContainer initializes and starts the Killgrave container, setting up imposters and request dumping.
120126
// It also configures cleanup for the container and logs the external and internal endpoints for access.
121-
//
122-
// Deprecated: Use Parrot instead
123127
func (k *Killgrave) StartContainer() error {
124128
err := k.setupImposters()
125129
if err != nil {

lib/docker/test_env/parrot.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/google/uuid"
89
"github.com/rs/zerolog"
910
"github.com/rs/zerolog/log"
1011
tc "github.com/testcontainers/testcontainers-go"
@@ -29,6 +30,18 @@ type Parrot struct {
2930
l zerolog.Logger
3031
}
3132

33+
// ParrotAdapterResponse imitates the standard response from a Chainlink external adapter.
34+
type ParrotAdapterResponse struct {
35+
ID string `json:"id"`
36+
Data ParrotAdapterResult `json:"data"`
37+
Error any `json:"error"`
38+
}
39+
40+
// ParrotAdapterResult is the data field of the ParrotAdapterResponse.
41+
type ParrotAdapterResult struct {
42+
Result any `json:"result"`
43+
}
44+
3245
// NewParrot creates a new instance of ParrotServer with specified networks and options.
3346
// It initializes the server with a unique container name and a default startup timeout.
3447
// This function is useful for testing decentralized applications in a controlled environment.
@@ -134,3 +147,27 @@ func (p *Parrot) getContainerRequest() (tc.ContainerRequest, error) {
134147
},
135148
}, nil
136149
}
150+
151+
// SetAdapterRoute sets a new route for the mock external adapter, wrapping the provided response in a standard adapter response.
152+
func (p *Parrot) SetAdapterRoute(route *parrot.Route) error {
153+
var result any
154+
if route.RawResponseBody != "" {
155+
result = route.RawResponseBody
156+
} else {
157+
result = route.ResponseBody
158+
}
159+
ar := ParrotAdapterResponse{
160+
ID: uuid.NewString(),
161+
Data: ParrotAdapterResult{
162+
Result: result,
163+
},
164+
Error: nil,
165+
}
166+
167+
return p.Client.RegisterRoute(&parrot.Route{
168+
Method: route.Method,
169+
Path: route.Path,
170+
ResponseBody: ar,
171+
ResponseStatusCode: route.ResponseStatusCode,
172+
})
173+
}

0 commit comments

Comments
 (0)