test(releaseprep): add failing migration test suite

This commit is contained in:
Micheal Wilkinson
2026-03-20 18:22:45 +00:00
commit 2060af6a78
3 changed files with 189 additions and 0 deletions

13
go.mod Normal file
View File

@@ -0,0 +1,13 @@
module git.hrafn.xyz/aether/vociferate
go 1.26
toolchain go1.26.1
require github.com/stretchr/testify v1.10.0
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

10
go.sum Normal file
View File

@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -0,0 +1,166 @@
package releaseprep_test
import (
"os"
"path/filepath"
"testing"
"git.hrafn.xyz/aether/vociferate/internal/releaseprep"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type PrepareSuite struct {
suite.Suite
rootDir string
}
func TestPrepareSuite(t *testing.T) {
suite.Run(t, new(PrepareSuite))
}
func (s *PrepareSuite) SetupTest() {
s.rootDir = s.T().TempDir()
versionDir := filepath.Join(s.rootDir, "internal", "releaseprep", "version")
require.NoError(s.T(), os.MkdirAll(versionDir, 0o755))
require.NoError(s.T(), os.WriteFile(
filepath.Join(versionDir, "version.go"),
[]byte("package version\n\nconst String = \"1.1.6\"\n"),
0o644,
))
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n### Breaking\n\n### Added\n\n- New thing.\n\n### Fixed\n\n- Old thing.\n\n## [1.1.6] - 2017-12-20\n\n### Fixed\n\n- Historical note.\n"),
0o644,
))
}
func (s *PrepareSuite) TestPrepare_UpdatesVersionAndPromotesUnreleasedNotes() {
err := releaseprep.Prepare(s.rootDir, "v1.1.7", "2026-03-20", releaseprep.Options{})
require.NoError(s.T(), err)
versionBytes, err := os.ReadFile(filepath.Join(s.rootDir, "internal", "releaseprep", "version", "version.go"))
require.NoError(s.T(), err)
require.Equal(s.T(), "package version\n\nconst String = \"1.1.7\"\n", string(versionBytes))
changelogBytes, err := os.ReadFile(filepath.Join(s.rootDir, "changelog.md"))
require.NoError(s.T(), err)
require.Equal(s.T(), "# Changelog\n\n## [Unreleased]\n\n## [1.1.7] - 2026-03-20\n\n### Breaking\n\n### Added\n\n- New thing.\n\n### Fixed\n\n- Old thing.\n\n## [1.1.6] - 2017-12-20\n\n### Fixed\n\n- Historical note.\n", string(changelogBytes))
}
func (s *PrepareSuite) TestPrepare_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 := releaseprep.Prepare(s.rootDir, "1.1.7", "2026-03-20", releaseprep.Options{})
require.ErrorContains(s.T(), err, "unreleased section")
}
func (s *PrepareSuite) TestPrepare_ReturnsErrorWhenUnreleasedSectionIsEmpty() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n## [1.1.6] - 2017-12-20\n"),
0o644,
))
err := releaseprep.Prepare(s.rootDir, "1.1.7", "2026-03-20", releaseprep.Options{})
require.ErrorContains(s.T(), err, "unreleased section is empty")
}
func (s *PrepareSuite) TestRecommendedTag_UsesMinorBumpWhenAddedEntriesExist() {
tag, err := releaseprep.RecommendedTag(s.rootDir, releaseprep.Options{})
require.NoError(s.T(), err)
require.Equal(s.T(), "v1.2.0", tag)
}
func (s *PrepareSuite) TestRecommendedTag_UsesPatchBumpForFixOnlyChanges() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n### Fixed\n\n- Patch note.\n\n## [1.1.6] - 2017-12-20\n"),
0o644,
))
tag, err := releaseprep.RecommendedTag(s.rootDir, releaseprep.Options{})
require.NoError(s.T(), err)
require.Equal(s.T(), "v1.1.7", tag)
}
func (s *PrepareSuite) TestRecommendedTag_UsesMajorBumpWhenRemovedEntriesExist() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n### Removed\n\n- Breaking removal.\n\n## [1.1.6] - 2017-12-20\n"),
0o644,
))
tag, err := releaseprep.RecommendedTag(s.rootDir, releaseprep.Options{})
require.NoError(s.T(), err)
require.Equal(s.T(), "v2.0.0", tag)
}
func (s *PrepareSuite) TestRecommendedTag_UsesMajorBumpWhenBreakingEntriesExist() {
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n### Breaking\n\n- Changed API contract.\n\n### Changed\n\n- Updated defaults.\n\n## [1.1.6] - 2017-12-20\n"),
0o644,
))
tag, err := releaseprep.RecommendedTag(s.rootDir, releaseprep.Options{})
require.NoError(s.T(), err)
require.Equal(s.T(), "v2.0.0", tag)
}
func (s *PrepareSuite) TestPrepare_UsesCustomVersionFileAndPattern() {
customVersionFile := filepath.Join("custom", "VERSION.txt")
require.NoError(s.T(), os.MkdirAll(filepath.Join(s.rootDir, "custom"), 0o755))
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, customVersionFile),
[]byte("VERSION=1.1.6\n"),
0o644,
))
err := releaseprep.Prepare(s.rootDir, "1.1.8", "2026-03-20", releaseprep.Options{
VersionFile: customVersionFile,
VersionPattern: `VERSION=([^\n]+)`,
})
require.NoError(s.T(), err)
versionBytes, err := os.ReadFile(filepath.Join(s.rootDir, customVersionFile))
require.NoError(s.T(), err)
require.Equal(s.T(), "VERSION=1.1.8\n", string(versionBytes))
}
func (s *PrepareSuite) TestRecommendedTag_UsesCustomVersionFileAndPattern() {
customVersionFile := filepath.Join("custom", "VERSION.txt")
require.NoError(s.T(), os.MkdirAll(filepath.Join(s.rootDir, "custom"), 0o755))
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, customVersionFile),
[]byte("VERSION=2.3.4\n"),
0o644,
))
require.NoError(s.T(), os.WriteFile(
filepath.Join(s.rootDir, "changelog.md"),
[]byte("# Changelog\n\n## [Unreleased]\n\n### Added\n\n- Feature.\n\n## [2.3.4] - 2026-03-10\n"),
0o644,
))
tag, err := releaseprep.RecommendedTag(s.rootDir, releaseprep.Options{
VersionFile: customVersionFile,
VersionPattern: `VERSION=([^\n]+)`,
})
require.NoError(s.T(), err)
require.Equal(s.T(), "v2.4.0", tag)
}