The strategy list moves into the engine (AllStrategies), where the API and frontend will read it too: one source of truth, per the handoff. main shrinks to the standard Go shell pattern: all work happens in run(out io.Writer) error; main only maps the error to stderr and the exit code. Writing to an interface instead of stdout is what lets main_test.go capture output in a bytes.Buffer. errcheck flagged every unchecked Fprintf, so formatting became pure Sprintf string building with one checked write at the end: nicer than discarding four errors with '_, _ ='.
21 lines
522 B
Go
21 lines
522 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// run writes to an io.Writer instead of straight to stdout precisely so
|
|
// this test can hand it a buffer and inspect the output.
|
|
func TestRunPrintsAllScenarios(t *testing.T) {
|
|
var output bytes.Buffer
|
|
if err := run(&output); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, want := range []string{"none", "random", "most-connected", "illustrative"} {
|
|
if !strings.Contains(output.String(), want) {
|
|
t.Errorf("output is missing %q:\n%s", want, output.String())
|
|
}
|
|
}
|
|
}
|