Some checks failed
Go / build-and-release (push) Has been cancelled
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>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGetSerialById(t *testing.T) {
|
|
// Use shared database (skips in short mode)
|
|
db, _ := GetSharedDB(t)
|
|
savedEvents := GetSharedEvents(t)
|
|
|
|
if len(savedEvents) < 4 {
|
|
t.Fatalf("Need at least 4 saved events, got %d", len(savedEvents))
|
|
}
|
|
testEvent := savedEvents[3]
|
|
|
|
// Get the serial by ID
|
|
serial, err := db.GetSerialById(testEvent.ID)
|
|
if err != nil {
|
|
t.Fatalf("Failed to get serial by ID: %v", err)
|
|
}
|
|
|
|
// Verify the serial is not nil
|
|
if serial == nil {
|
|
t.Fatal("Expected serial to be non-nil, but got nil")
|
|
}
|
|
|
|
// Test with a non-existent ID
|
|
nonExistentId := make([]byte, len(testEvent.ID))
|
|
// Ensure it's different from any real ID
|
|
for i := range nonExistentId {
|
|
nonExistentId[i] = ^testEvent.ID[i]
|
|
}
|
|
|
|
serial, err = db.GetSerialById(nonExistentId)
|
|
if err == nil {
|
|
t.Fatalf("Expected error for non-existent ID, but got none")
|
|
}
|
|
|
|
// For non-existent Ids, the function should return nil serial and an error
|
|
if serial != nil {
|
|
t.Fatalf("Expected nil serial for non-existent ID, but got: %v", serial)
|
|
}
|
|
}
|