Skip to content

Commit 55eabdd

Browse files
committed
test(bench): cover the RenderBenchPage delegator; drop an unreachable branch
codecov/patch flagged benchpage.go at 90.24%. Two fixes bring it to 100%: - The happy-path test now calls the package-level RenderBenchPage (the public API) rather than the method, so the delegator's success path is covered within this package's own coverage profile (the CLI test that exercised it lives in a different package). - githubURLForRelativeTarget's `if rel == ""` guard was unreachable: the leading-'#' check above it means any '#' found sits at index >= 1, so rel is never empty after the split. Removed it (a defensive branch must be drivable red/green) and noted the invariant in a comment.
1 parent 34e1aa9 commit 55eabdd

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

internal/release/benchpage.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ func githubURLForRelativeTarget(target, srcDirRel string) (string, bool) {
8383
if i := strings.IndexByte(target, '#'); i >= 0 {
8484
rel, frag = target[:i], target[i:]
8585
}
86-
if rel == "" {
87-
return "", false
88-
}
86+
// rel is always non-empty here: the guard above rejects a
87+
// leading '#', so any '#' found sits at index >= 1.
8988
resolved := path.Join(srcDirRel, rel)
9089
if strings.HasSuffix(rel, "/") {
9190
resolved += "/"

internal/release/benchpage_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ func TestRenderBenchPageHappyPath(t *testing.T) {
9999
require.NoError(t, os.WriteFile(readme,
100100
[]byte("# Bench\n\nReproduce with [`run.sh`](run.sh).\n"), 0o644))
101101

102+
// Exercise the package-level delegator (the public API) so its
103+
// success path is covered within this package's profile.
102104
out := filepath.Join(root, "pages", "benchmark.md")
103-
require.NoError(t, New().RenderBenchPage(root, out))
105+
require.NoError(t, RenderBenchPage(root, out))
104106

105107
got, err := os.ReadFile(out)
106108
require.NoError(t, err)

0 commit comments

Comments
 (0)