Files
next.orly.dev/pkg/database/export_test.go
mleku 24383ef1f4
Some checks failed
Go / build-and-release (push) Has been cancelled
Decompose handle-event.go into DDD domain services (v0.36.15)
Major refactoring of event handling into clean, testable domain services:

- Add pkg/event/validation: JSON hex validation, signature verification,
  timestamp bounds, NIP-70 protected tag validation
- Add pkg/event/authorization: Policy and ACL authorization decisions,
  auth challenge handling, access level determination
- Add pkg/event/routing: Event router registry with ephemeral and delete
  handlers, kind-based dispatch
- Add pkg/event/processing: Event persistence, delivery to subscribers,
  and post-save hooks (ACL reconfig, sync, relay groups)
- Reduce handle-event.go from 783 to 296 lines (62% reduction)
- Add comprehensive unit tests for all new domain services
- Refactor database tests to use shared TestMain setup
- Fix blossom URL test expectations (missing "/" separator)
- Add go-memory-optimization skill and analysis documentation
- Update DDD_ANALYSIS.md to reflect completed decomposition

Files modified:
- app/handle-event.go: Slim orchestrator using domain services
- app/server.go: Service initialization and interface wrappers
- app/handle-event-types.go: Shared types (OkHelper, result types)
- pkg/event/validation/*: New validation service package
- pkg/event/authorization/*: New authorization service package
- pkg/event/routing/*: New routing service package
- pkg/event/processing/*: New processing service package
- pkg/database/*_test.go: Refactored to shared TestMain
- pkg/blossom/http_test.go: Fixed URL format expectations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 05:30:07 +01:00

53 lines
1.3 KiB
Go

package database
import (
"bufio"
"bytes"
"testing"
"git.mleku.dev/mleku/nostr/encoders/event"
"lol.mleku.dev/chk"
)
// TestExport tests the Export function by:
// 1. Using the shared database with events from examples.Cache
// 2. Checking that events can be exported
// 3. Verifying the exported events can be parsed
func TestExport(t *testing.T) {
// Use shared database (skips in short mode)
db, ctx := GetSharedDB(t)
savedEvents := GetSharedEvents(t)
t.Logf("Shared database has %d events", len(savedEvents))
// Test 1: Export all events and verify they can be parsed
var exportBuffer bytes.Buffer
db.Export(ctx, &exportBuffer)
// Parse the exported events and count them
exportedIDs := make(map[string]bool)
exportScanner := bufio.NewScanner(&exportBuffer)
exportScanner.Buffer(make([]byte, 0, 1_000_000_000), 1_000_000_000)
exportCount := 0
for exportScanner.Scan() {
b := exportScanner.Bytes()
ev := event.New()
if _, err := ev.Unmarshal(b); chk.E(err) {
t.Fatal(err)
}
exportedIDs[string(ev.ID)] = true
exportCount++
}
// Check for scanner errors
if err := exportScanner.Err(); err != nil {
t.Fatalf("Scanner error: %v", err)
}
t.Logf("Found %d events in the export", exportCount)
// Verify we exported a reasonable number of events
if exportCount == 0 {
t.Fatal("Export returned no events")
}
}