tstest/natlab/vmtest: add helpers for fatal step errors (#19753)

In a lot of places, we construct an error to End a step, then immediately log
it to the governing test as test fatal. Save ourselves a bit of boilerplate by
putting methods on Step for that.

There are a couple cases this doesn't cover, e.g., where we construct the Step
outside a subtest that wants to fail individually, but it helps enough to pay
for its lines.

Updates #13038

Change-Id: I71f9900942962de16609b6b198d3ba13d6958a5f
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
M. J. Fromberger
2026-05-14 09:24:47 -07:00
committed by GitHub
parent 8203edc099
commit 4eb977413a
2 changed files with 40 additions and 47 deletions
+18
View File
@@ -129,6 +129,24 @@ func (s *Step) End(err error) {
s.env.publishStepChange(s)
}
// Fatalf marks the step as failed (as [Step.End]), and then logs a test
// failure to the environment's test, with an error constructed from the given
// arguments.
func (s *Step) Fatalf(msg string, args ...any) {
s.Fatal(fmt.Errorf(msg, args...))
}
// Fatal marks the step as failed (as [Step.End]), and then logs a test failure
// to the environment's test, with the specified (non-nil) error. It will panic
// if err == nil.
func (s *Step) Fatal(err error) {
if err == nil {
panic(fmt.Sprintf("Step %q: Fatal called with a nil error", s.name))
}
s.End(err)
s.env.t.Fatal(err)
}
// EventType identifies the kind of event published to the EventBus.
type EventType string