- Add GET /api/changelog endpoint to fetch changelog from CHANGELOG.md - Create service/changelog.go to parse CHANGELOG.md markdown file - Add handler/changelog.go to handle changelog requests - Update ChangelogDrawer component to fetch from API instead of hardcoded data - Export apiFetch from lib/api.ts for public use - Add changelog parser tests with 14 version entries verified
39 lines
843 B
Go
39 lines
843 B
Go
package service
|
||
|
||
import (
|
||
"os"
|
||
"testing"
|
||
)
|
||
|
||
func TestParseChangelog(t *testing.T) {
|
||
// 设置项目根目录
|
||
os.Setenv("PROJECT_ROOT", "../..")
|
||
|
||
changelog, err := ParseChangelog()
|
||
if err != nil {
|
||
t.Fatalf("ParseChangelog failed: %v", err)
|
||
}
|
||
|
||
if len(changelog) == 0 {
|
||
t.Fatal("No changelog entries parsed")
|
||
}
|
||
|
||
// 验证第一个条目(应该是 1.4.0)
|
||
firstEntry := changelog[0]
|
||
t.Logf("First entry: v%s - %s", firstEntry.Version, firstEntry.Date)
|
||
|
||
if firstEntry.Version != "1.4.0" {
|
||
t.Errorf("Expected first version to be 1.4.0, got %s", firstEntry.Version)
|
||
}
|
||
|
||
if len(firstEntry.Changes) == 0 {
|
||
t.Error("First entry has no changes")
|
||
}
|
||
|
||
// 打印所有版本
|
||
t.Logf("Total versions: %d", len(changelog))
|
||
for _, entry := range changelog {
|
||
t.Logf(" - v%s: %d categories", entry.Version, len(entry.Changes))
|
||
}
|
||
}
|