Files
stamp/internal/changelog/changelog_test.go
Thomas 77462f5e8a feat: initial stamp implementation
- stamp add: create .stamp/*.md changeset files (interactive + --no-interactive)
- stamp status: show pending stamps and projected next versions (plain + --json)
- stamp version: consume stamps, bump semver, update CHANGELOGs, commit
- stamp publish: create git tags, GitHub/Gitea releases, upload artifacts
- stamp comment: post/update idempotent PR comments via GitHub/Gitea API
- Supports monorepos via stamp.toml [[projects]] blocks
- Changeset files support YAML (---) and TOML (+++) frontmatter
- Semver + pre-release support (alpha, beta, rc)
- Examples and workflow documentation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-08 20:56:23 +01:00

108 lines
2.4 KiB
Go

package changelog_test
import (
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/thokra/stamp/internal/changelog"
)
var testDate = time.Date(2026, 3, 8, 0, 0, 0, 0, time.UTC)
func TestAppend_NewFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "CHANGELOG.md")
err := changelog.Append(path, changelog.Entry{
Version: "1.0.0",
Date: testDate,
Description: "Initial release",
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
data, _ := os.ReadFile(path)
content := string(data)
if !strings.Contains(content, "## [1.0.0] - 2026-03-08") {
t.Errorf("expected version header, got:\n%s", content)
}
if !strings.Contains(content, "Initial release") {
t.Errorf("expected description in changelog")
}
}
func TestAppend_ExistingFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "CHANGELOG.md")
// Write first version.
_ = changelog.Append(path, changelog.Entry{
Version: "1.0.0",
Date: testDate,
Description: "First release",
})
// Append second version.
_ = changelog.Append(path, changelog.Entry{
Version: "1.1.0",
Date: testDate.Add(24 * time.Hour),
Description: "Second release",
})
data, _ := os.ReadFile(path)
content := string(data)
if !strings.Contains(content, "## [1.0.0]") {
t.Error("expected 1.0.0 section")
}
if !strings.Contains(content, "## [1.1.0]") {
t.Error("expected 1.1.0 section")
}
// New version should appear before old.
idx110 := strings.Index(content, "## [1.1.0]")
idx100 := strings.Index(content, "## [1.0.0]")
if idx110 > idx100 {
t.Error("expected 1.1.0 to appear before 1.0.0 (newest first)")
}
}
func TestAppend_EmptyDescription(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "CHANGELOG.md")
err := changelog.Append(path, changelog.Entry{
Version: "2.0.0",
Date: testDate,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
data, _ := os.ReadFile(path)
if !strings.Contains(string(data), "## [2.0.0]") {
t.Error("expected version header even with empty description")
}
}
func TestAppend_CreatesDirectory(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "sub", "dir", "CHANGELOG.md")
err := changelog.Append(path, changelog.Entry{
Version: "1.0.0",
Date: testDate,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if _, err := os.Stat(path); err != nil {
t.Errorf("expected file to be created: %v", err)
}
}