Skip to content

Commit cb77a11

Browse files
committed
JD fork test example
1 parent 2943192 commit cb77a11

File tree

12 files changed

+104
-243
lines changed

12 files changed

+104
-243
lines changed

framework/components/blockchain/aptos.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,18 @@ func newAptos(in *Input) (*Output, error) {
103103
if err != nil {
104104
return nil, err
105105
}
106+
107+
dc, err := framework.NewDockerClient()
108+
if err != nil {
109+
return nil, err
110+
}
106111
cmdStr := []string{"aptos", "init", "--network=local", "--assume-yes", fmt.Sprintf("--private-key=%s", DefaultAptosPrivateKey)}
107-
_, err = framework.ExecContainer(containerName, cmdStr)
112+
_, err = dc.ExecContainer(containerName, cmdStr)
108113
if err != nil {
109114
return nil, err
110115
}
111116
fundCmd := []string{"aptos", "account", "fund-with-faucet", "--account", DefaultAptosAccount, "--amount", "1000000000000"}
112-
_, err = framework.ExecContainer(containerName, fundCmd)
117+
_, err = dc.ExecContainer(containerName, fundCmd)
113118
if err != nil {
114119
return nil, err
115120
}

framework/components/blockchain/sui.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func fundAccount(url string, address string) error {
5555
// generateKeyData generates a wallet and returns all the data
5656
func generateKeyData(containerName string, keyCipherType string) (*SuiWalletInfo, error) {
5757
cmdStr := []string{"sui", "keytool", "generate", keyCipherType, "--json"}
58-
keyOut, err := framework.ExecContainer(containerName, cmdStr)
58+
dc, err := framework.NewDockerClient()
59+
if err != nil {
60+
return nil, err
61+
}
62+
keyOut, err := dc.ExecContainer(containerName, cmdStr)
5963
if err != nil {
6064
return nil, err
6165
}

framework/components/jd/jd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type Input struct {
3434

3535
type Output struct {
3636
UseCache bool `toml:"use_cache"`
37+
ContainerName string `toml:"container_name"`
38+
DBContainerName string `toml:"db_container_name"`
3739
ExternalGRPCUrl string `toml:"grpc_url"`
3840
InternalGRPCUrl string `toml:"internal_grpc_url"`
3941
ExternalWSRPCUrl string `toml:"wsrpc_url"`
@@ -123,6 +125,8 @@ func NewJD(in *Input) (*Output, error) {
123125
}
124126
out := &Output{
125127
UseCache: true,
128+
ContainerName: containerName,
129+
DBContainerName: pgOut.ContainerName,
126130
ExternalGRPCUrl: fmt.Sprintf("%s:%s", host, in.GRPCPort),
127131
InternalGRPCUrl: fmt.Sprintf("%s:%s", containerName, in.GRPCPort),
128132
ExternalWSRPCUrl: fmt.Sprintf("%s:%s", host, in.WSRPCPort),

framework/docker.go

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,51 @@ func NewDockerClient() (*DockerClient, error) {
112112
return &DockerClient{cli: cli}, nil
113113
}
114114

115+
// ExecContainer executes a command inside a running container by name and returns the combined stdout/stderr.
116+
func (dc *DockerClient) ExecContainer(containerName string, command []string) (string, error) {
117+
L.Info().Strs("Command", command).Str("ContainerName", containerName).Msg("Executing command")
118+
ctx := context.Background()
119+
containers, err := dc.cli.ContainerList(ctx, container.ListOptions{
120+
All: true,
121+
})
122+
if err != nil {
123+
return "", fmt.Errorf("failed to list containers: %w", err)
124+
}
125+
var containerID string
126+
for _, cont := range containers {
127+
for _, name := range cont.Names {
128+
if name == "/"+containerName {
129+
containerID = cont.ID
130+
break
131+
}
132+
}
133+
}
134+
if containerID == "" {
135+
return "", fmt.Errorf("container with name '%s' not found", containerName)
136+
}
137+
138+
execConfig := container.ExecOptions{
139+
Cmd: command,
140+
AttachStdout: true,
141+
AttachStderr: true,
142+
}
143+
execID, err := dc.cli.ContainerExecCreate(ctx, containerID, execConfig)
144+
if err != nil {
145+
return "", fmt.Errorf("failed to create exec instance: %w", err)
146+
}
147+
resp, err := dc.cli.ContainerExecAttach(ctx, execID.ID, container.ExecStartOptions{})
148+
if err != nil {
149+
return "", fmt.Errorf("failed to attach to exec instance: %w", err)
150+
}
151+
defer resp.Close()
152+
output, err := io.ReadAll(resp.Reader)
153+
if err != nil {
154+
return "", fmt.Errorf("failed to read exec output: %w", err)
155+
}
156+
L.Info().Str("Output", string(output)).Msg("Command output")
157+
return string(output), nil
158+
}
159+
115160
// CopyFile copies a file into a container by name
116161
func (dc *DockerClient) CopyFile(containerName, sourceFile, targetPath string) error {
117162
ctx := context.Background()
@@ -340,55 +385,6 @@ func RemoveTestContainers() error {
340385
return nil
341386
}
342387

343-
// ExecContainer executes a command inside a running container by name and returns the combined stdout/stderr.
344-
func ExecContainer(containerName string, command []string) (string, error) {
345-
L.Info().Strs("Command", command).Str("ContainerName", containerName).Msg("Executing command")
346-
p, err := tc.NewDockerProvider()
347-
if err != nil {
348-
return "", err
349-
}
350-
ctx := context.Background()
351-
containers, err := p.Client().ContainerList(ctx, container.ListOptions{
352-
All: true,
353-
})
354-
if err != nil {
355-
return "", fmt.Errorf("failed to list containers: %w", err)
356-
}
357-
var containerID string
358-
for _, cont := range containers {
359-
for _, name := range cont.Names {
360-
if name == "/"+containerName {
361-
containerID = cont.ID
362-
break
363-
}
364-
}
365-
}
366-
if containerID == "" {
367-
return "", fmt.Errorf("container with name '%s' not found", containerName)
368-
}
369-
370-
execConfig := container.ExecOptions{
371-
Cmd: command,
372-
AttachStdout: true,
373-
AttachStderr: true,
374-
}
375-
execID, err := p.Client().ContainerExecCreate(ctx, containerID, execConfig)
376-
if err != nil {
377-
return "", fmt.Errorf("failed to create exec instance: %w", err)
378-
}
379-
resp, err := p.Client().ContainerExecAttach(ctx, execID.ID, container.ExecStartOptions{})
380-
if err != nil {
381-
return "", fmt.Errorf("failed to attach to exec instance: %w", err)
382-
}
383-
defer resp.Close()
384-
output, err := io.ReadAll(resp.Reader)
385-
if err != nil {
386-
return "", fmt.Errorf("failed to read exec output: %w", err)
387-
}
388-
L.Info().Str("Output", string(output)).Msg("Command output")
389-
return string(output), nil
390-
}
391-
392388
type ContainerResources struct {
393389
CPUs float64 `toml:"cpus" validate:"gte=0"`
394390
MemoryMb uint `toml:"memory_mb"`

framework/examples/myproject/smoke_aptos_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func TestAptosSmoke(t *testing.T) {
2626
_ = blockchain.DefaultAptosAccount
2727
_ = blockchain.DefaultAptosPrivateKey
2828

29-
_, err = framework.ExecContainer(bc.ContainerName, []string{"ls", "-lah"})
29+
dc, err := framework.NewDockerClient()
30+
require.NoError(t, err)
31+
32+
_, err = dc.ExecContainer(bc.ContainerName, []string{"ls", "-lah"})
3033
require.NoError(t, err)
3134

3235
t.Run("test something", func(t *testing.T) {

framework/examples/myproject/smoke_sui_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ func TestSuiSmoke(t *testing.T) {
3636
_ = bc.NetworkSpecificData.SuiAccount.SuiAddress
3737

3838
// execute any additional commands, to deploy contracts or set up
39-
_, err = framework.ExecContainer(bc.ContainerName, []string{"ls", "-lah"})
39+
dc, err := framework.NewDockerClient()
40+
require.NoError(t, err)
41+
_, err = dc.ExecContainer(bc.ContainerName, []string{"ls", "-lah"})
4042
require.NoError(t, err)
4143

4244
_, err = fake.NewFakeDataProvider(in.MockerDataProvider)

framework/examples/myproject_cll/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
These examples require either internal images or access to our repositories.
44

55

6-
## Developing
6+
## Job Distributor
7+
Checkout Job Distributor repository and build an image
8+
```
9+
docker build -t job-distributor:0.9.0 -f e2e/Dockerfile.e2e .
10+
```
11+
712
Run the tests locally
813
```
9-
CTF_CONFIGS=jd.toml go test -v -run TestJD
14+
CTF_CONFIGS=jd.toml go test -v -count 1 -run TestJD
1015
```

framework/examples/myproject_cll/go.mod

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
1818
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
1919
github.com/Microsoft/go-winio v0.6.2 // indirect
20-
github.com/avast/retry-go/v4 v4.6.1 // indirect
2120
github.com/aws/aws-sdk-go-v2 v1.32.5 // indirect
2221
github.com/aws/aws-sdk-go-v2/config v1.28.4 // indirect
2322
github.com/aws/aws-sdk-go-v2/credentials v1.17.45 // indirect
@@ -32,28 +31,17 @@ require (
3231
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect
3332
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 // indirect
3433
github.com/aws/smithy-go v1.22.1 // indirect
35-
github.com/bits-and-blooms/bitset v1.17.0 // indirect
3634
github.com/block-vision/sui-go-sdk v1.0.6 // indirect
3735
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
38-
github.com/consensys/bavard v0.1.22 // indirect
39-
github.com/consensys/gnark-crypto v0.14.0 // indirect
4036
github.com/containerd/log v0.1.0 // indirect
4137
github.com/containerd/platforms v0.2.1 // indirect
4238
github.com/cpuguy83/dockercfg v0.3.2 // indirect
43-
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
44-
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
4539
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
46-
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
47-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
4840
github.com/distribution/reference v0.6.0 // indirect
4941
github.com/docker/docker v27.3.0+incompatible // indirect
5042
github.com/docker/go-connections v0.5.0 // indirect
5143
github.com/docker/go-units v0.5.0 // indirect
52-
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
53-
github.com/ethereum/go-ethereum v1.15.0 // indirect
54-
github.com/ethereum/go-verkle v0.2.2 // indirect
5544
github.com/felixge/httpsnoop v1.0.4 // indirect
56-
github.com/fsnotify/fsnotify v1.7.0 // indirect
5745
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
5846
github.com/go-logr/logr v1.4.2 // indirect
5947
github.com/go-logr/stdr v1.2.2 // indirect
@@ -64,16 +52,14 @@ require (
6452
github.com/go-resty/resty/v2 v2.15.3 // indirect
6553
github.com/gogo/protobuf v1.3.2 // indirect
6654
github.com/google/uuid v1.6.0 // indirect
67-
github.com/gorilla/websocket v1.5.1 // indirect
6855
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
69-
github.com/holiman/uint256 v1.3.2 // indirect
7056
github.com/klauspost/compress v1.17.9 // indirect
57+
github.com/kr/pretty v0.3.1 // indirect
7158
github.com/leodido/go-urn v1.4.0 // indirect
7259
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
7360
github.com/magiconair/properties v1.8.7 // indirect
7461
github.com/mattn/go-colorable v0.1.13 // indirect
7562
github.com/mattn/go-isatty v0.0.20 // indirect
76-
github.com/mmcloughlin/addchain v0.4.0 // indirect
7763
github.com/moby/docker-image-spec v1.3.1 // indirect
7864
github.com/moby/patternmatcher v0.6.0 // indirect
7965
github.com/moby/sys/sequential v0.5.0 // indirect
@@ -87,16 +73,11 @@ require (
8773
github.com/pkg/errors v0.9.1 // indirect
8874
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
8975
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
90-
github.com/prometheus/client_golang v1.20.4 // indirect
91-
github.com/prometheus/common v0.62.0 // indirect
9276
github.com/rogpeppe/go-internal v1.13.1 // indirect
93-
github.com/rs/cors v1.9.0 // indirect
9477
github.com/rs/zerolog v1.33.0 // indirect
95-
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
9678
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
9779
github.com/shoenig/go-m1cpu v0.1.6 // indirect
9880
github.com/sirupsen/logrus v1.9.3 // indirect
99-
github.com/supranational/blst v0.3.13 // indirect
10081
github.com/testcontainers/testcontainers-go v0.35.0 // indirect
10182
github.com/tidwall/gjson v1.14.4 // indirect
10283
github.com/tidwall/match v1.1.1 // indirect
@@ -112,7 +93,6 @@ require (
11293
go.opentelemetry.io/otel/trace v1.32.0 // indirect
11394
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
11495
golang.org/x/crypto v0.32.0 // indirect
115-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
11696
golang.org/x/net v0.34.0 // indirect
11797
golang.org/x/sync v0.10.0 // indirect
11898
golang.org/x/sys v0.29.0 // indirect
@@ -122,7 +102,5 @@ require (
122102
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
123103
google.golang.org/grpc v1.68.0 // indirect
124104
google.golang.org/protobuf v1.36.1 // indirect
125-
gopkg.in/guregu/null.v4 v4.0.0 // indirect
126105
gopkg.in/yaml.v3 v3.0.1 // indirect
127-
rsc.io/tmplfunc v0.0.3 // indirect
128106
)

0 commit comments

Comments
 (0)