Skip to content

Commit 9cfdf7c

Browse files
committed
Init
1 parent 2497a60 commit 9cfdf7c

File tree

7 files changed

+185
-7
lines changed

7 files changed

+185
-7
lines changed

lib/client/mockserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
// MockserverClient mockserver client
18+
// Deprecated: Use Parrot instead
1819
type MockserverClient struct {
1920
APIClient *resty.Client
2021
Config *MockserverConfig
@@ -28,6 +29,7 @@ type MockserverConfig struct {
2829
}
2930

3031
// ConnectMockServer creates a connection to a deployed mockserver in the environment
32+
// Deprecated: Use Parrot instead
3133
func ConnectMockServer(e *environment.Environment) *MockserverClient {
3234
c := NewMockserverClient(&MockserverConfig{
3335
LocalURL: e.URLs[mockserver.LocalURLsKey][0],
@@ -37,6 +39,7 @@ func ConnectMockServer(e *environment.Environment) *MockserverClient {
3739
}
3840

3941
// ConnectMockServerURL creates a connection to a mockserver at a given url, should only be used for inside K8s tests
42+
// Deprecated: Use Parrot instead
4043
func ConnectMockServerURL(url string) *MockserverClient {
4144
c := NewMockserverClient(&MockserverConfig{
4245
LocalURL: url,
@@ -46,6 +49,7 @@ func ConnectMockServerURL(url string) *MockserverClient {
4649
}
4750

4851
// NewMockserverClient returns a mockserver client
52+
// Deprecated: Use Parrot instead
4953
func NewMockserverClient(cfg *MockserverConfig) *MockserverClient {
5054
log.Debug().Str("Local URL", cfg.LocalURL).Str("Remote URL", cfg.ClusterURL).Msg("Connected to MockServer")
5155
isDebug := os.Getenv("RESTY_DEBUG") == "true"

lib/docker/test_env/killgrave.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
const defaultKillgraveImage = "friendsofgo/killgrave:v0.5.1-request-dump"
2828

29+
// Deprecated: Use Parrot instead
2930
type Killgrave struct {
3031
EnvComponent
3132
ExternalEndpoint string
@@ -82,6 +83,7 @@ type KillgraveAdapterResult struct {
8283
// NewKillgrave initializes a new Killgrave instance with specified networks and imposters directory.
8384
// It sets default configurations and allows for optional environment component modifications.
8485
// This function is useful for creating a Killgrave service for testing and simulating APIs.
86+
// Deprecated: Use Parrot instead
8587
func NewKillgrave(networks []string, impostersDirectoryPath string, opts ...EnvComponentOption) *Killgrave {
8688
k := &Killgrave{
8789
EnvComponent: EnvComponent{

lib/docker/test_env/mockserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
const defaultMockServerImage = "mockserver/mockserver:5.15.0"
2424

25+
// Deprecated: Use Parrot instead
2526
type MockServer struct {
2627
EnvComponent
2728
Client *ctfClient.MockserverClient
@@ -35,6 +36,7 @@ type MockServer struct {
3536
// NewMockServer creates a new instance of MockServer with specified networks and options.
3637
// It initializes the server with a unique container name and a default startup timeout.
3738
// This function is useful for testing decentralized applications in a controlled environment.
39+
// Deprecated: Use Parrot instead
3840
func NewMockServer(networks []string, opts ...EnvComponentOption) *MockServer {
3941
ms := &MockServer{
4042
EnvComponent: EnvComponent{

lib/docker/test_env/parrot.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package test_env
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
"time"
7+
8+
"github.com/google/uuid"
9+
"github.com/rs/zerolog"
10+
"github.com/rs/zerolog/log"
11+
"github.com/smartcontractkit/chainlink-testing-framework/lib/docker"
12+
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
13+
"github.com/smartcontractkit/chainlink-testing-framework/lib/mirror"
14+
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
15+
"github.com/smartcontractkit/chainlink-testing-framework/parrot"
16+
tc "github.com/testcontainers/testcontainers-go"
17+
tcwait "github.com/testcontainers/testcontainers-go/wait"
18+
)
19+
20+
const defaultParrotImage = "parrot:latest"
21+
22+
// Parrot is a test environment component that wraps a Parrot server.
23+
type Parrot struct {
24+
EnvComponent
25+
Client *parrot.Client
26+
ExternalEndpoint string
27+
InternalEndpoint string
28+
t *testing.T
29+
l zerolog.Logger
30+
}
31+
32+
// NewParrot creates a new instance of ParrotServer with specified networks and options.
33+
// It initializes the server with a unique container name and a default startup timeout.
34+
// This function is useful for testing decentralized applications in a controlled environment.
35+
func NewParrot(networks []string, opts ...EnvComponentOption) *Parrot {
36+
p := &Parrot{
37+
EnvComponent: EnvComponent{
38+
ContainerName: fmt.Sprintf("%s-%s", "parrot", uuid.NewString()[0:8]),
39+
Networks: networks,
40+
StartupTimeout: 1 * time.Minute,
41+
},
42+
l: log.Logger,
43+
}
44+
for _, opt := range opts {
45+
opt(&p.EnvComponent)
46+
}
47+
return p
48+
}
49+
50+
// WithTestInstance configures the MockServer with a test logger and test context.
51+
// It returns the updated MockServer instance for use in testing scenarios.
52+
func (p *Parrot) WithTestInstance(t *testing.T) *Parrot {
53+
p.l = logging.GetTestLogger(t)
54+
p.t = t
55+
return p
56+
}
57+
58+
// SetExternalAdapterMocks configures a specified number of mock external adapter endpoints.
59+
// It generates unique paths for each adapter and stores their URLs for later use.
60+
// This function is useful for testing scenarios that require multiple external adapter interactions.
61+
func (p *Parrot) SetExternalAdapterMocks(count int) error {
62+
// for i := 0; i < count; i++ {
63+
// path := fmt.Sprintf("/ea-%d", i)
64+
// err := ms.Client.SetRandomValuePath(path)
65+
// if err != nil {
66+
// return err
67+
// }
68+
// cName, err := ms.Container.Name(testcontext.Get(ms.t))
69+
// if err != nil {
70+
// return err
71+
// }
72+
// cName = strings.Replace(cName, "/", "", -1)
73+
// eaUrl, err := url.Parse(fmt.Sprintf("http://%s:%s%s",
74+
// cName, "1080", path))
75+
// if err != nil {
76+
// return err
77+
// }
78+
// ms.EAMockUrls = append(ms.EAMockUrls, eaUrl)
79+
// }
80+
// return nil
81+
return fmt.Errorf("not implemented")
82+
}
83+
84+
// StartContainer initializes and starts a Parrot container.
85+
// It sets up logging, retrieves the container request, and establishes endpoints for communication.
86+
// This function is essential for testing environments that require a mock server instance.
87+
func (p *Parrot) StartContainer() error {
88+
l := logging.GetTestContainersGoTestLogger(p.t)
89+
cr, err := p.getContainerRequest()
90+
if err != nil {
91+
return err
92+
}
93+
c, err := docker.StartContainerWithRetry(p.l, tc.GenericContainerRequest{
94+
ContainerRequest: cr,
95+
Reuse: true,
96+
Started: true,
97+
Logger: l,
98+
})
99+
if err != nil {
100+
return fmt.Errorf("cannot start MockServer container: %w", err)
101+
}
102+
p.Container = c
103+
endpoint, err := GetEndpoint(testcontext.Get(p.t), c, "http")
104+
if err != nil {
105+
return err
106+
}
107+
p.ExternalEndpoint = endpoint
108+
p.InternalEndpoint = fmt.Sprintf("http://%s", p.ContainerName)
109+
110+
p.Client = parrot.NewClient(p.ExternalEndpoint)
111+
112+
p.l.Info().Str("External Endpoint", p.ExternalEndpoint).
113+
Str("Internal Endpoint", p.InternalEndpoint).
114+
Str("Container Name", p.ContainerName).
115+
Msg("Started Parrot Container")
116+
return nil
117+
}
118+
119+
func (p *Parrot) getContainerRequest() (tc.ContainerRequest, error) {
120+
pImage := mirror.AddMirrorToImageIfSet(defaultParrotImage)
121+
122+
return tc.ContainerRequest{
123+
Name: p.ContainerName,
124+
Image: pImage,
125+
ExposedPorts: []string{"80/tcp"},
126+
Networks: p.Networks,
127+
WaitingFor: tcwait.ForHealthCheck().
128+
WithPollInterval(100 * time.Millisecond).WithStartupTimeout(p.StartupTimeout),
129+
LifecycleHooks: []tc.ContainerLifecycleHooks{
130+
{
131+
PostStarts: p.PostStartsHooks,
132+
PostStops: p.PostStopsHooks,
133+
},
134+
},
135+
}, nil
136+
}

lib/docker/test_env/parrot_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package test_env
2+
3+
import (
4+
"testing"
5+
6+
"github.com/smartcontractkit/chainlink-testing-framework/lib/docker"
7+
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestParrot(t *testing.T) {
12+
t.Parallel()
13+
14+
l := logging.GetTestLogger(t)
15+
network, err := docker.CreateNetwork(l)
16+
require.NoError(t, err)
17+
18+
p := NewParrot([]string{network.Name}).WithTestInstance(t)
19+
err = p.StartContainer()
20+
require.NoError(t, err)
21+
}

lib/go.mod

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/smartcontractkit/chainlink-testing-framework/lib
22

3-
go 1.23
3+
go 1.23.4
4+
5+
toolchain go1.23.6
46

57
require (
68
dario.cat/mergo v1.0.1
@@ -16,7 +18,7 @@ require (
1618
github.com/docker/docker v27.3.1+incompatible
1719
github.com/docker/go-connections v0.5.0
1820
github.com/ethereum/go-ethereum v1.14.11
19-
github.com/go-resty/resty/v2 v2.15.3
21+
github.com/go-resty/resty/v2 v2.16.3
2022
github.com/google/go-github/v41 v41.0.0
2123
github.com/google/uuid v1.6.0
2224
github.com/imdario/mergo v0.3.16
@@ -32,14 +34,15 @@ require (
3234
github.com/prometheus/common v0.60.0
3335
github.com/rs/zerolog v1.33.0
3436
github.com/slack-go/slack v0.15.0
37+
github.com/smartcontractkit/chainlink-testing-framework/parrot v0.4.1
3538
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10
3639
github.com/spf13/cobra v1.8.1
3740
github.com/spf13/pflag v1.0.5
3841
github.com/stretchr/testify v1.9.0
3942
github.com/testcontainers/testcontainers-go v0.35.0
4043
go.uber.org/atomic v1.11.0
4144
go.uber.org/zap v1.27.0
42-
golang.org/x/net v0.30.0
45+
golang.org/x/net v0.33.0
4346
golang.org/x/oauth2 v0.23.0
4447
golang.org/x/sync v0.10.0
4548
golang.org/x/text v0.21.0
@@ -50,6 +53,11 @@ require (
5053
k8s.io/kubectl v0.31.2
5154
)
5255

56+
require (
57+
github.com/go-chi/chi v1.5.5 // indirect
58+
github.com/rs/xid v1.5.0 // indirect
59+
)
60+
5361
require (
5462
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
5563
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect

lib/go.sum

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG
178178
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
179179
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
180180
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
181+
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
182+
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
181183
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
182184
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
183185
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -198,8 +200,8 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
198200
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
199201
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
200202
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
201-
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
202-
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
203+
github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
204+
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
203205
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
204206
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
205207
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
@@ -444,6 +446,7 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
444446
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
445447
github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE=
446448
github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
449+
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
447450
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
448451
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
449452
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
@@ -463,6 +466,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
463466
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
464467
github.com/slack-go/slack v0.15.0 h1:LE2lj2y9vqqiOf+qIIy0GvEoxgF1N5yLGZffmEZykt0=
465468
github.com/slack-go/slack v0.15.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
469+
github.com/smartcontractkit/chainlink-testing-framework/parrot v0.4.1 h1:7qTB+oMH+j1jwb95oDE76SzY1ddxwdmjcpO2nXNop+I=
470+
github.com/smartcontractkit/chainlink-testing-framework/parrot v0.4.1/go.mod h1:xl7qVV9vMen/06rRjWOvUoYbx9fPNBlBqDzvSzq4Flk=
466471
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10 h1:Yf+n3T/fnUWcYyfe7bsygV4sWAkNo0QhN58APJFIKIc=
467472
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10/go.mod h1:05duR85P8YHuIfIkA7sn2bvrhKo/pDpFKV2rliYHNOo=
468473
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
@@ -570,8 +575,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
570575
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
571576
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
572577
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
573-
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
574-
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
578+
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
579+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
575580
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
576581
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
577582
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=

0 commit comments

Comments
 (0)