Skip to content

Commit 6684a0b

Browse files
committed
ignore healthCommands, those go via healthcheck anyway
1 parent bf8dc28 commit 6684a0b

2 files changed

Lines changed: 25 additions & 46 deletions

File tree

pkg/containertest/yaml_runner.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var (
1818
checkHealthFn = CheckHealth
1919
checkWaitsFn = CheckWaits
2020
checkFilesExistFn = CheckFilesExist
21-
checkHealthCommandsFn = CheckHealthCommands
2221
checkStandardRunFn = CheckStandardRun
2322
checkRunnerOutputFn = CheckRunnerOutput
2423
)
@@ -149,7 +148,7 @@ func buildRunnerContainerConfig(runner RunnerConfig, base *ContainerConfig, yaml
149148
// For each runner:
150149
// - If expectedOutput is non-empty, an output check is performed first.
151150
// - If runTests is true (the default when omitted), the normal check sequence follows:
152-
// health (when tcp/http/healthCommands are configured) → file → tcp/http waits → healthCommands → standardRun.
151+
// health (when tcp/http are configured) → file → tcp/http waits → standardRun.
153152
// - If runTests is explicitly false, health/file/wait/health-command checks are skipped,
154153
// but a standard container run is still performed for that runner.
155154
//
@@ -161,13 +160,7 @@ func RunChecksFromYAML(ctx context.Context, image string, yamlPath string, conta
161160
return err
162161
}
163162

164-
logInfo("Loaded container test YAML: path=%s runners=%d http=%d tcp=%d healthCommands=%d", yamlPath, len(config.Runners), len(config.HTTP), len(config.TCP), len(config.HealthCommands))
165-
166-
for index, command := range config.HealthCommands {
167-
if strings.TrimSpace(command.Command) == "" {
168-
return fmt.Errorf("healthCommands[%d].command must not be empty", index)
169-
}
170-
}
163+
logInfo("Loaded container test YAML: path=%s runners=%d http=%d tcp=%d", yamlPath, len(config.Runners), len(config.HTTP), len(config.TCP))
171164

172165
for index, mount := range config.Mounts {
173166
trimmedPath := strings.TrimSpace(mount.Path)
@@ -186,7 +179,7 @@ func RunChecksFromYAML(ctx context.Context, image string, yamlPath string, conta
186179
runners = []RunnerConfig{{}}
187180
}
188181

189-
hasHealthCheckPreconditions := len(config.HTTP) > 0 || len(config.TCP) > 0 || len(config.HealthCommands) > 0
182+
hasHealthCheckPreconditions := len(config.HTTP) > 0 || len(config.TCP) > 0
190183

191184
for i, runner := range runners {
192185
runnerFilePath := strings.TrimSpace(runner.FilePath)
@@ -244,14 +237,14 @@ func RunChecksFromYAML(ctx context.Context, image string, yamlPath string, conta
244237
continue
245238
}
246239

247-
// Normal check sequence: health (when tcp/http/healthCommands are configured) → file → tcp/http waits → healthCommands → standardRun.
240+
// Normal check sequence: health (when tcp/http are configured) → file → tcp/http waits → standardRun.
248241
if hasHealthCheckPreconditions {
249242
logInfo("Runner[%d]: running health check", i)
250243
if err := checkHealthFn(healthCtx, image, runnerCfg); err != nil {
251244
return err
252245
}
253246
} else {
254-
logInfo("Runner[%d]: skipping health check (no tcp/http/healthCommands configured)", i)
247+
logInfo("Runner[%d]: skipping health check (no tcp/http configured)", i)
255248
}
256249

257250
if runnerFilePath != "" {
@@ -268,13 +261,6 @@ func RunChecksFromYAML(ctx context.Context, image string, yamlPath string, conta
268261
}
269262
}
270263

271-
if len(config.HealthCommands) > 0 {
272-
logInfo("Runner[%d]: running health commands (%d)", i, len(config.HealthCommands))
273-
if err := checkHealthCommandsFn(runnerCtx, image, runnerCfg, config.HealthCommands); err != nil {
274-
return err
275-
}
276-
}
277-
278264
logInfo("Runner[%d]: running standard run check", i)
279265
if err := checkStandardRunFn(runnerCtx, image, runnerCfg); err != nil {
280266
return err

pkg/containertest/yaml_runner_test.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ func setYAMLRunnerSeams(t *testing.T) {
2020
oldHealth := checkHealthFn
2121
oldWaits := checkWaitsFn
2222
oldFiles := checkFilesExistFn
23-
oldHealthCommands := checkHealthCommandsFn
2423
oldStandardRun := checkStandardRunFn
2524
oldRunnerOutput := checkRunnerOutputFn
2625
t.Cleanup(func() {
2726
loadContainerTestYAMLFn = oldLoad
2827
checkHealthFn = oldHealth
2928
checkWaitsFn = oldWaits
3029
checkFilesExistFn = oldFiles
31-
checkHealthCommandsFn = oldHealthCommands
3230
checkStandardRunFn = oldStandardRun
3331
checkRunnerOutputFn = oldRunnerOutput
3432
})
@@ -157,13 +155,6 @@ func TestRunChecksFromYAMLValidationAndErrors(t *testing.T) {
157155
t.Fatalf("expected standard run error")
158156
}
159157

160-
loadContainerTestYAMLFn = func(string) (ContainerTestYAML, error) {
161-
return ContainerTestYAML{HealthCommands: []HealthCommandTestConfig{{Command: " "}}}, nil
162-
}
163-
if err := RunChecksFromYAML(ctx, "img", "cfg.yaml", nil); err == nil || !strings.Contains(err.Error(), "healthCommands[0].command") {
164-
t.Fatalf("expected health command validation error, got %v", err)
165-
}
166-
167158
loadContainerTestYAMLFn = func(string) (ContainerTestYAML, error) {
168159
return ContainerTestYAML{Runners: []RunnerConfig{{FilePath: " "}}}, nil
169160
}
@@ -205,14 +196,23 @@ func TestRunChecksFromYAMLValidationAndErrors(t *testing.T) {
205196
}
206197

207198
loadContainerTestYAMLFn = func(string) (ContainerTestYAML, error) {
208-
return ContainerTestYAML{HealthCommands: []HealthCommandTestConfig{{Command: "mycommand"}}}, nil
199+
return ContainerTestYAML{HealthCommands: []HealthCommandTestConfig{{Command: " "}}}, nil
209200
}
210-
checkFilesExistFn = CheckFilesExist
211-
checkHealthCommandsFn = func(context.Context, string, *ContainerConfig, []HealthCommandTestConfig) error {
212-
return errors.New("health commands boom")
201+
checkFilesExistFn = func(context.Context, string, []string, *ContainerConfig) error {
202+
t.Fatalf("did not expect file checks")
203+
return nil
213204
}
214-
if err := RunChecksFromYAML(ctx, "img", "cfg.yaml", nil); err == nil {
215-
t.Fatalf("expected health commands error")
205+
checkWaitsFn = func(context.Context, string, []HTTPTestConfig, []TCPTestConfig, *ContainerConfig) error {
206+
t.Fatalf("did not expect wait checks")
207+
return nil
208+
}
209+
checkHealthFn = func(context.Context, string, *ContainerConfig) error {
210+
t.Fatalf("did not expect health check")
211+
return nil
212+
}
213+
checkStandardRunFn = func(context.Context, string, *ContainerConfig) error { return nil }
214+
if err := RunChecksFromYAML(ctx, "img", "cfg.yaml", nil); err != nil {
215+
t.Fatalf("expected healthCommands to be ignored, got %v", err)
216216
}
217217
}
218218

@@ -289,7 +289,6 @@ func TestRunChecksFromYAMLCallsAllCheckTypes(t *testing.T) {
289289
calledHealth := 0
290290
calledWaits := 0
291291
calledFiles := 0
292-
calledHealthCommands := 0
293292
calledStandardRun := 0
294293

295294
loadContainerTestYAMLFn = func(string) (ContainerTestYAML, error) {
@@ -300,7 +299,6 @@ func TestRunChecksFromYAMLCallsAllCheckTypes(t *testing.T) {
300299
TimeoutSeconds: 1,
301300
FilePath: "/etc/hosts",
302301
}},
303-
HealthCommands: []HealthCommandTestConfig{{Command: "mycommand", ExpectedExitCode: intPtr(7), ExpectedContent: "ok", MatchContent: true}},
304302
}, nil
305303
}
306304

@@ -329,11 +327,6 @@ func TestRunChecksFromYAMLCallsAllCheckTypes(t *testing.T) {
329327
callOrder = append(callOrder, "files")
330328
return nil
331329
}
332-
checkHealthCommandsFn = func(context.Context, string, *ContainerConfig, []HealthCommandTestConfig) error {
333-
calledHealthCommands++
334-
callOrder = append(callOrder, "healthCommands")
335-
return nil
336-
}
337330
checkStandardRunFn = func(context.Context, string, *ContainerConfig) error {
338331
calledStandardRun++
339332
return nil
@@ -343,13 +336,13 @@ func TestRunChecksFromYAMLCallsAllCheckTypes(t *testing.T) {
343336
t.Fatalf("unexpected run error: %v", err)
344337
}
345338

346-
if calledHealth != 1 || calledWaits != 1 || calledFiles != 1 || calledHealthCommands != 1 || calledStandardRun != 1 {
347-
t.Fatalf("expected all checks once, got health=%d waits=%d files=%d healthCommands=%d standardRun=%d", calledHealth, calledWaits, calledFiles, calledHealthCommands, calledStandardRun)
339+
if calledHealth != 1 || calledWaits != 1 || calledFiles != 1 || calledStandardRun != 1 {
340+
t.Fatalf("expected all checks once, got health=%d waits=%d files=%d standardRun=%d", calledHealth, calledWaits, calledFiles, calledStandardRun)
348341
}
349342

350-
// New order: health → files → waits → healthCommands
351-
if len(callOrder) < 4 || callOrder[0] != "health" || callOrder[1] != "files" || callOrder[2] != "waits" || callOrder[3] != "healthCommands" {
352-
t.Fatalf("expected health→files→waits→healthCommands call order, got %v", callOrder)
343+
// New order: health → files → waits
344+
if len(callOrder) < 3 || callOrder[0] != "health" || callOrder[1] != "files" || callOrder[2] != "waits" {
345+
t.Fatalf("expected health→files→waits call order, got %v", callOrder)
353346
}
354347
}
355348

0 commit comments

Comments
 (0)