test(version): add arm for empty vcs.revision guard #53

Closed
opened 2026-08-06 14:46:30 +02:00 by pilot · 0 comments
Owner

Surveyor found this during PR#51 review (review 4983, approved).

The s.Value != "" guard in String() has no dedicated test. Removing it makes all five existing arms still pass — because the arms that inject a non-empty vcs.revision don't exercise the empty case, and the dev-fallback arm injects no vcs.revision at all.

Missing arm: inject vcs.revision = "" (key present, value empty) and verify String() returns "dev", not "".

func TestString_VCSRevision_EmptyValue(t *testing.T) {
    defer resetTag("")()
    defer injectBuildInfo(func() (*debug.BuildInfo, bool) {
        return &debug.BuildInfo{Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: ""}}}, true
    })()
    if got := String(); got != "dev" {
        t.Errorf("String() = %q, want %q (empty vcs.revision must fall through to dev)", got, "dev")
    }
}

Proof that this arm catches the mutation: removing s.Value != "" makes the empty-value case return "", which fails this test.

Surveyor provided the fix; carry-forward from PR#51 per "freeze on first approval" discipline.

Surveyor found this during PR#51 review (review 4983, approved). The `s.Value != ""` guard in `String()` has no dedicated test. Removing it makes all five existing arms still pass — because the arms that inject a non-empty `vcs.revision` don't exercise the empty case, and the dev-fallback arm injects no `vcs.revision` at all. **Missing arm**: inject `vcs.revision = ""` (key present, value empty) and verify `String()` returns `"dev"`, not `""`. ```go func TestString_VCSRevision_EmptyValue(t *testing.T) { defer resetTag("")() defer injectBuildInfo(func() (*debug.BuildInfo, bool) { return &debug.BuildInfo{Settings: []debug.BuildSetting{{Key: "vcs.revision", Value: ""}}}, true })() if got := String(); got != "dev" { t.Errorf("String() = %q, want %q (empty vcs.revision must fall through to dev)", got, "dev") } } ``` Proof that this arm catches the mutation: removing `s.Value != ""` makes the empty-value case return `""`, which fails this test. Surveyor provided the fix; carry-forward from PR#51 per "freeze on first approval" discipline.
pilot closed this issue 2026-08-06 14:51:23 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
frankenbit/purser#53
No description provided.