repo mirror list: harden --sort test assertions · Entire
repo mirror list: harden --sort test assertions
c1dfc27→main·
gtrrz-victor·1w ago·1 file·+45 added/-26 removed
Two test gaps the review flagged:
- Ordering checks used require.Less(strings.Index(a), strings.Index(b)), which passes when the earlier substring is absent (Index returns -1, and -1 < anyPresentIndex). Add a requireOrder helper that asserts presence before order, and route every ordering check through it.
- The --show-available filter+sort test filtered down to one row before --sort ran, so the sort was never observed and a deleted/mis-wired sortAvailable call would still pass. Keep two rows after the filter and assert access orders read before write.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
01KX0BW5ZTM66F20FMJ1Z2NW5DView transcript
Changes
1
cmd/entire/cli
Mrepo_mirror_test.go+45/-26
496 unmodified lines
return err
}
// requireOrder asserts each needle appears in s, in the given order. It guards
// presence first: strings.Index returns -1 for an absent needle, so a bare
// index comparison would pass when the earlier needle is missing entirely
// (-1 < anyPresentIndex). This fails loudly instead.
func requireOrder(t *testing.T, s string, needles ...string) {
t.Helper()
prev := -1
for _, n := range needles {
i := strings.Index(s, n)
require.GreaterOrEqualf(t, i, 0, "expected %q in output", n)
require.Greaterf(t, i, prev, "expected %q to come after the previous item", n)
prev = i
}
}
// TestRepoMirrorList_FilterSort pins the client-side --repo filter and --sort
// applied to `repo mirror list` before rendering (server handles
// owner/provider/cluster), so they shape both the table and --json output and
... // omitted for brevity
}
Mcmd/entire/cli/repo_mirror_test.go+45/-26