Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 48418e5

Browse files
committed
fixup! fixup! fixup! Simplify assertion type
1 parent ba77461 commit 48418e5

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

ci/tcli/tcli.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,41 +174,41 @@ func (r *ContainerRunner) RunCmd(cmd *exec.Cmd) *Assertable {
174174
// Assert runs the Assertable and
175175
func (a Assertable) Assert(t *testing.T, option ...Assertion) {
176176
slog.Helper()
177-
var cmdResult CommandResult
178-
179177
var (
180178
stdout bytes.Buffer
181179
stderr bytes.Buffer
180+
result CommandResult
182181
)
183182

184183
a.cmd.Stdout = &stdout
185184
a.cmd.Stderr = &stderr
186185

187186
start := time.Now()
188187
err := a.cmd.Run()
189-
cmdResult.Duration = time.Since(start)
188+
result.Duration = time.Since(start)
190189

191190
if exitErr, ok := err.(*exec.ExitError); ok {
192-
cmdResult.ExitCode = exitErr.ExitCode()
191+
result.ExitCode = exitErr.ExitCode()
193192
} else if err != nil {
194-
cmdResult.ExitCode = -1
193+
// TODO: handle this case better
194+
result.ExitCode = -1
195195
} else {
196-
cmdResult.ExitCode = 0
196+
result.ExitCode = 0
197197
}
198198

199-
cmdResult.Stdout = stdout.Bytes()
200-
cmdResult.Stderr = stderr.Bytes()
199+
result.Stdout = stdout.Bytes()
200+
result.Stderr = stderr.Bytes()
201201

202202
slogtest.Info(t, "command output",
203203
slog.F("command", a.cmd),
204-
slog.F("stdout", string(cmdResult.Stdout)),
205-
slog.F("stderr", string(cmdResult.Stderr)),
206-
slog.F("exit-code", cmdResult.ExitCode),
207-
slog.F("duration", cmdResult.Duration),
204+
slog.F("stdout", string(result.Stdout)),
205+
slog.F("stderr", string(result.Stderr)),
206+
slog.F("exit_code", result.ExitCode),
207+
slog.F("duration", result.Duration),
208208
)
209209

210210
for _, assertion := range option {
211-
assertion(t, &cmdResult)
211+
assertion(t, &result)
212212
}
213213
}
214214

@@ -288,21 +288,18 @@ func StderrMatches(pattern string) Assertion {
288288

289289
func matches(t *testing.T, name, pattern string, target []byte) {
290290
slog.Helper()
291+
fields := []slog.Field{
292+
slog.F("pattern", pattern),
293+
slog.F("target", string(target)),
294+
slog.F("sink", name),
295+
}
291296

292297
ok, err := regexp.Match(pattern, target)
293298
if err != nil {
294-
slogtest.Fatal(t, "failed to attempt regexp match", slog.Error(err),
295-
slog.F("pattern", pattern),
296-
slog.F("target", string(target)),
297-
slog.F("sink", name),
298-
)
299+
slogtest.Fatal(t, "failed to attempt regexp match", append(fields, slog.Error(err))...)
299300
}
300301
if !ok {
301-
slogtest.Fatal(t, "expected to find pattern, no match found",
302-
slog.F("pattern", pattern),
303-
slog.F("target", string(target)),
304-
slog.F("sink", name),
305-
)
302+
slogtest.Fatal(t, "expected to find pattern, no match found", fields...)
306303
}
307304
}
308305

0 commit comments

Comments
 (0)