Files
mesh-catalog/modules/nats/cmd/mesh-nats-snapshot/dockerguard_test.go
T
jschoubben cf071270a0
mesh/delivery superseded: a newer head of the same pull request
mesh/check failed: integration: mesh-delivery-gate/cmd/mesh-delivery-gate.TestAPassingVerdictAsksTheApproveAndItsApproveMergesWithinSecondsOverARealBu…
Skip the docker tests where the daemon is unreachable, not only where the binary is missing
The checker's integration level runs shut off, so docker is found but its daemon
is not, and TestTheDeclaredDumpRunsInTheBussImage failed the group check on g14
(issue 1823). MESH_REQUIRE_DOCKER=1 still fails.
2026-10-23 14:41:00 +02:00

54 lines
1.7 KiB
Go

package main
import (
"fmt"
"testing"
)
// dockerVerdict decides what a test that starts containers does: run, skip or fail. found is the result of looking
// the docker program up, probeErr the result of asking the daemon for its version (nil when it answered). The checker's
// integration level runs shut off (no network, no /run), so on a build node the program is found and the daemon is not
// reachable; that is a skip, not a failure, except where docker is required (MESH_REQUIRE_DOCKER=1).
func dockerVerdict(found bool, lookErr, probeErr error, required bool) (action, reason string) {
var why string
switch {
case !found:
why = fmt.Sprintf("there is no docker in this toolchain (%v)", lookErr)
case probeErr != nil:
why = fmt.Sprintf("no docker daemon is reachable from here (%v)", probeErr)
default:
return "run", ""
}
if required {
return "fail", "MESH_REQUIRE_DOCKER=1 and " + why
}
return "skip", why
}
func TestDockerVerdict(t *testing.T) {
boom := fmt.Errorf("cannot connect")
cases := []struct {
name string
found bool
look, probe error
required bool
want string
}{
{"answers", true, nil, nil, false, "run"},
{"answers, required", true, nil, nil, true, "run"},
{"no program", false, boom, nil, false, "skip"},
{"no program, required", false, boom, nil, true, "fail"},
{"program but no daemon", true, nil, boom, false, "skip"},
{"program but no daemon, required", true, nil, boom, true, "fail"},
}
for _, c := range cases {
got, why := dockerVerdict(c.found, c.look, c.probe, c.required)
if got != c.want {
t.Errorf("%s: got %s, want %s", c.name, got, c.want)
}
if got != "run" && why == "" {
t.Errorf("%s: no reason given", c.name)
}
}
}