Files
sow-tools/internal/changelog/changelog_test.go
T
2026-05-06 13:51:00 +02:00

80 lines
1.8 KiB
Go

package changelog
import "testing"
func TestSanitizeSubject(t *testing.T) {
t.Parallel()
tests := []struct {
name string
subject string
want string
}{
{
name: "merge prefix with quotes",
subject: "Merge pull request 'Add classes overhaul (#123)'",
want: "Add classes overhaul",
},
{
name: "plain subject",
subject: "Add classes overhaul (#123)",
want: "Add classes overhaul",
},
{
name: "double quotes",
subject: `Merge pull request "Add classes overhaul (#123)"`,
want: "Add classes overhaul",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := sanitizeSubject(tt.subject); got != tt.want {
t.Fatalf("sanitizeSubject(%q) = %q, want %q", tt.subject, got, tt.want)
}
})
}
}
func TestOwnerAndRepoFromURL(t *testing.T) {
t.Parallel()
owner, repo, err := ownerAndRepoFromURL("https://gitea.example.test/org/repo.git")
if err != nil {
t.Fatalf("ownerAndRepoFromURL returned error: %v", err)
}
if owner != "org" || repo != "repo" {
t.Fatalf("ownerAndRepoFromURL returned %q/%q", owner, repo)
}
}
func TestDeriveAPIBaseURL(t *testing.T) {
t.Parallel()
got := deriveAPIBaseURL("https://gitea.example.test/org/repo")
want := "https://gitea.example.test/api/v1"
if got != want {
t.Fatalf("deriveAPIBaseURL() = %q, want %q", got, want)
}
}
func TestNormalizeAPIBaseURL(t *testing.T) {
t.Parallel()
tests := []struct {
input string
want string
}{
{input: "https://gitea.example.test", want: "https://gitea.example.test/api/v1"},
{input: "https://gitea.example.test/api/v1", want: "https://gitea.example.test/api/v1"},
}
for _, tt := range tests {
if got := normalizeAPIBaseURL(tt.input); got != tt.want {
t.Fatalf("normalizeAPIBaseURL(%q) = %q, want %q", tt.input, got, tt.want)
}
}
}