Skip to content

Commit c85333a

Browse files
authored
fetch container names once (#25)
1 parent 9b4e1c2 commit c85333a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

runner.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,21 @@ func BuildTestRunners(cfg config.Config, opt TestRunnerOptions) (TestRunners, er
8484
}
8585

8686
infra := make(map[string][]config.ServiceConfig)
87-
infraComposeFiles := make([]string, 0, len(cfg.Infrastructure)+len(t.Infrastructure))
8887
for k, v := range cfg.Infrastructure {
8988
infra[k] = append(infra[k], v)
90-
infraComposeFiles = append(infraComposeFiles, collectDockerComposeFiles(v)...)
9189
}
9290
for k, v := range t.Infrastructure {
9391
infra[k] = append(infra[k], v)
94-
infraComposeFiles = append(infraComposeFiles, collectDockerComposeFiles(v)...)
9592
}
9693

97-
var infraContainers []string
98-
if len(infra) > 0 {
99-
var err error
100-
infraContainers, err = findContainerNames(context.Background(), infraComposeFiles)
94+
infraContainers := make(map[string][]string)
95+
for k, v := range infra {
96+
f := collectDockerComposeFiles(v...)
97+
containers, err := findContainerNames(context.Background(), f)
10198
if err != nil {
102-
return nil, fmt.Errorf("failed to find infrastructure container names: %w", err)
99+
return nil, fmt.Errorf("failed to find infrastructure container names for %s: %w", k, err)
103100
}
101+
infraContainers[k] = containers
104102
}
105103

106104
toolNames := slices.Collect(maps.Keys(cfg.Tools))
@@ -370,7 +368,7 @@ type TestRunner struct {
370368
tools []config.ServiceConfig
371369
collectors []metrics.Collector
372370

373-
infrastructureContainers []string
371+
infrastructureContainers map[string][]string
374372
toolContainers []string
375373

376374
name string
@@ -422,7 +420,13 @@ func (r *TestRunner) Infrastructure() map[string][]config.ServiceConfig {
422420
}
423421

424422
func (r *TestRunner) InfrastructureContainers() []string {
425-
return r.infrastructureContainers
423+
return fold(
424+
maps.Values(r.infrastructureContainers),
425+
nil,
426+
func(result []string, containers []string) []string {
427+
return append(result, containers...)
428+
},
429+
)
426430
}
427431

428432
func (r *TestRunner) Tools() []config.ServiceConfig {
@@ -565,11 +569,7 @@ func (r *TestRunner) runInfrastructure(ctx context.Context) (err error) {
565569
paths := collectDockerComposeFiles(infraConfigs...)
566570

567571
logger.Info("Running infrastructure", "name", k, "log-path", logPath)
568-
containers, err := findContainerNames(ctx, paths)
569-
if err != nil {
570-
return fmt.Errorf("failed finding container names for paths %v: %w", paths, err)
571-
}
572-
err = r.dockerComposeUpWait(ctx, logger, paths, containers, logPath)
572+
err = r.dockerComposeUpWait(ctx, logger, paths, r.infrastructureContainers[k], logPath)
573573
if err != nil {
574574
return fmt.Errorf("failed to start infrastructure: %w", err)
575575
}

0 commit comments

Comments
 (0)