102 lines
3.8 KiB
Go
102 lines
3.8 KiB
Go
package publish
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/bundle"
|
|
"gitea.maximumdirect.net/eric/distributor/internal/config"
|
|
"gitea.maximumdirect.net/eric/distributor/internal/storage"
|
|
"gitea.maximumdirect.net/eric/distributor/internal/storage/fake"
|
|
)
|
|
|
|
func TestPlanOutputsRejectsCollision(t *testing.T) {
|
|
sourceBackend := fake.New()
|
|
if _, err := sourceBackend.WriteFile(context.Background(), "report.md", []byte("# Report\n"), storage.WriteOptions{}); err != nil {
|
|
t.Fatalf("WriteFile report.md error = %v", err)
|
|
}
|
|
if _, err := sourceBackend.WriteFile(context.Background(), "report.html", []byte("<p>source html</p>\n"), storage.WriteOptions{}); err != nil {
|
|
t.Fatalf("WriteFile report.html error = %v", err)
|
|
}
|
|
reportDigest := bundle.FileDigest([]byte("# Report\n"))
|
|
htmlDigest := bundle.FileDigest([]byte("<p>source html</p>\n"))
|
|
files := []bundle.ManifestFile{
|
|
{Path: "report.md", SHA256: reportDigest, Size: 9},
|
|
{Path: "report.html", SHA256: htmlDigest, Size: 19},
|
|
}
|
|
_, err := PlanOutputs(context.Background(), Request{
|
|
SourceBackend: sourceBackend,
|
|
SourceBundle: bundle.Bundle{
|
|
Manifest: bundle.Manifest{
|
|
SchemaVersion: 1,
|
|
ID: "bundle",
|
|
Created: time.Date(2026, 5, 30, 11, 10, 0, 0, time.UTC),
|
|
Digest: bundle.BundleDigest(files),
|
|
Files: files,
|
|
},
|
|
},
|
|
Publish: config.PublishPolicy{Source: true, HTML: true},
|
|
Transform: config.Transform{MarkdownToHTML: &config.MarkdownToHTML{Enabled: true, Mode: config.TransformModeSidecar}},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("PlanSourceOutputs() error = nil, want collision")
|
|
}
|
|
}
|
|
|
|
func TestPlanOutputsRejectsHTMLWithoutMarkdown(t *testing.T) {
|
|
sourceBackend := fake.New()
|
|
if _, err := sourceBackend.WriteFile(context.Background(), "summary.txt", []byte("Summary\n"), storage.WriteOptions{}); err != nil {
|
|
t.Fatalf("WriteFile summary.txt error = %v", err)
|
|
}
|
|
files := []bundle.ManifestFile{{Path: "summary.txt", SHA256: bundle.FileDigest([]byte("Summary\n")), Size: 8}}
|
|
_, err := PlanOutputs(context.Background(), Request{
|
|
SourceBackend: sourceBackend,
|
|
SourceBundle: bundle.Bundle{Manifest: bundle.Manifest{
|
|
SchemaVersion: 1,
|
|
ID: "bundle",
|
|
Created: time.Date(2026, 5, 30, 11, 10, 0, 0, time.UTC),
|
|
Digest: bundle.BundleDigest(files),
|
|
Files: files,
|
|
}},
|
|
Publish: config.PublishPolicy{HTML: true},
|
|
Transform: config.Transform{MarkdownToHTML: &config.MarkdownToHTML{Enabled: true, Mode: config.TransformModeSidecar}},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("PlanOutputs() error = nil, want no markdown failure")
|
|
}
|
|
}
|
|
|
|
func TestBuildRejectsHTMLWithoutTransform(t *testing.T) {
|
|
sourceBackend := fake.New()
|
|
destinationBackend := fake.New()
|
|
if _, err := sourceBackend.WriteFile(context.Background(), "report.md", []byte("# Report\n"), storage.WriteOptions{}); err != nil {
|
|
t.Fatalf("WriteFile report.md error = %v", err)
|
|
}
|
|
files := []bundle.ManifestFile{{Path: "report.md", SHA256: bundle.FileDigest([]byte("# Report\n")), Size: 9}}
|
|
_, err := Build(context.Background(), Request{
|
|
PipelineID: "reports",
|
|
DestinationID: "archive",
|
|
SourceBackend: sourceBackend,
|
|
DestinationBackend: destinationBackend,
|
|
DestinationBundlePath: "",
|
|
SourceBundle: bundle.Bundle{Manifest: bundle.Manifest{
|
|
SchemaVersion: 1,
|
|
ID: "bundle",
|
|
Created: time.Date(2026, 5, 30, 11, 10, 0, 0, time.UTC),
|
|
Digest: bundle.BundleDigest(files),
|
|
Files: files,
|
|
}},
|
|
Publish: config.PublishPolicy{HTML: true},
|
|
Transfer: config.TransferPolicy{
|
|
OnDestinationSame: config.TransferActionSkip,
|
|
OnDestinationOlder: config.TransferActionReplace,
|
|
OnDestinationNewer: config.TransferActionSkip,
|
|
OnConflict: config.TransferActionFail,
|
|
},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("Build() error = nil, want missing transform error")
|
|
}
|
|
}
|