chore(go): add unreleased changelog tests

This commit is contained in:
Micheal Wilkinson
2026-03-21 14:25:19 +00:00
parent 64a7b6d86b
commit b7d1760beb
2 changed files with 32 additions and 0 deletions

View File

@@ -23,6 +23,19 @@ func TestMainRecommendPrintsTag(t *testing.T) {
}
}
func TestMainPrintUnreleasedWritesPendingNotes(t *testing.T) {
root := t.TempDir()
writeFile(t, filepath.Join(root, "CHANGELOG.md"), "# Changelog\n\n## [Unreleased]\n\n### Added\n\n- Feature.\n\n### Fixed\n\n- Bugfix.\n\n## [1.1.6] - 2017-12-20\n")
stdout, stderr, code := runMain(t, "--print-unreleased", "--root", root)
if code != 0 {
t.Fatalf("expected exit 0, got %d (stderr: %s)", code, stderr)
}
if stdout != "### Added\n\n- Feature.\n\n### Fixed\n\n- Bugfix.\n" {
t.Fatalf("unexpected unreleased output: %q", stdout)
}
}
func TestMainUsageExitWhenRequiredFlagsMissing(t *testing.T) {
_, stderr, code := runMain(t)
if code != 2 {

View File

@@ -109,6 +109,25 @@ func (s *PrepareSuite) TestRecommendedTag_UsesMinorBumpWhenBreakingHeadingIsEmpt
require.Equal(s.T(), "v1.2.0", tag)
}
func (s *PrepareSuite) TestUnreleasedBody_ReturnsStructuredPendingReleaseNotes() {
body, err := vociferate.UnreleasedBody(s.rootDir, vociferate.Options{})
require.NoError(s.T(), err)
require.Equal(s.T(), "### Breaking\n\n### Added\n\n- New thing.\n\n### Fixed\n\n- Old thing.\n", body)
}
func (s *PrepareSuite) TestUnreleasedBody_ReturnsErrorWhenUnreleasedSectionMissing() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "CHANGELOG.md"),
[]byte("# Changelog\n\n## [1.1.6] - 2017-12-20\n"),
0o644,
))
_, err := vociferate.UnreleasedBody(s.rootDir, vociferate.Options{})
require.ErrorContains(s.T(), err, "unreleased section")
}
func (s *PrepareSuite) TestRecommendedTag_ReturnsErrorWhenUnreleasedHasOnlyTemplateHeadings() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "CHANGELOG.md"),