Skip to content

Commit

Permalink
test/integration: for TestLocalDevSetup / -dev, expose http ports
Browse files Browse the repository at this point in the history
  • Loading branch information
jchappelow committed Feb 29, 2024
1 parent a6050b1 commit 7654dc4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
File renamed without changes.
12 changes: 6 additions & 6 deletions test/integration/docker-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
node0:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 0}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down Expand Up @@ -67,7 +67,7 @@ services:
node1:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 1}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down Expand Up @@ -127,7 +127,7 @@ services:
node2:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 2}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down Expand Up @@ -190,7 +190,7 @@ services:
node3:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 3}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down Expand Up @@ -250,7 +250,7 @@ services:
node4:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 4}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down Expand Up @@ -310,7 +310,7 @@ services:
node5:
image: kwild:latest
ports:
- "8080"
- "{{with .ExposedHTTPPorts}}{{index . 5}}:{{end}}8080"
- "50051"
- "26656"
- "26657"
Expand Down
20 changes: 19 additions & 1 deletion test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type IntTestConfig struct {
DockerComposeOverrideFile string
GanacheComposeFile string
WithGanache bool
ExposedHTTPPorts bool

WaitTimeout time.Duration
LogLevel string
Expand Down Expand Up @@ -177,6 +178,12 @@ func WithNonValidators(n int) HelperOpt {
}
}

func WithExposedHTTPPorts() HelperOpt {
return func(r *IntHelper) {
r.cfg.ExposedHTTPPorts = true
}
}

func WithJoinExpiry(expiry int64) HelperOpt {
return func(r *IntHelper) {
r.cfg.JoinExpiry = expiry
Expand Down Expand Up @@ -512,11 +519,22 @@ func (r *IntHelper) prepareDockerCompose(ctx context.Context, tmpDir string) {
// docker-compose file is to use envs in docker-compose.yml, but it doesn't work
//r.updateEnv("KWIL_NETWORK", localNetworkName)

var exposedHTTPPorts []int
if r.cfg.ExposedHTTPPorts {
// Actually only need this as long as the number of nodes defined in
// the docker-compose.yml.template file. This is not related to
// NValidators and NNValidators.
for i := 0; i < 20; i++ { // more than enough, which is 6 presently
exposedHTTPPorts = append(exposedHTTPPorts, i+8080+1)
}
}

// here we generate a new docker-compose.yml file with the new network from template
composeFile := filepath.Join(tmpDir, "docker-compose.yml")
err = utils.CreateComposeFile(composeFile, "./docker-compose.yml.template",
utils.ComposeConfig{
Network: localNetworkName,
Network: localNetworkName,
ExposedHTTPPorts: exposedHTTPPorts,
})
require.NoError(r.t, err, "failed to create docker compose file")

Expand Down
1 change: 1 addition & 0 deletions test/integration/kwild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestLocalDevSetup(t *testing.T) {
integration.WithBlockInterval(time.Second),
integration.WithValidators(4),
integration.WithNonValidators(0),
integration.WithExposedHTTPPorts(),
}

helper := integration.NewIntHelper(t, opts...)
Expand Down
4 changes: 4 additions & 0 deletions test/utils/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

type ComposeConfig struct {
Network string
// ExposedHTTPPorts can be left empty to not expose any ports to the host,
// or set to the host ports to expose the http interface for each node. e.g.
// []int{8081, 8082, ...}
ExposedHTTPPorts []int
}

func genCompose(templateFile string, config ComposeConfig) (string, error) {
Expand Down

0 comments on commit 7654dc4

Please sign in to comment.