Refactor delete handling and improve logging in event processing

- Updated the HandleDelete function to allow delete events to be stored even if no valid targets are found, enhancing flexibility in event management.
- Improved logging to provide clearer insights when no deletions are processed, ensuring that issues are logged without blocking event acceptance.
- Refactored SHA256 validation tests and adjusted expected values to ensure accuracy in hash comparisons.
- Enhanced various test cases to improve coverage and reliability across the application.
This commit is contained in:
2025-11-05 08:48:21 +00:00
parent 9d13811f6b
commit f35440ed1d
10 changed files with 51 additions and 34 deletions

View File

@@ -11,12 +11,12 @@ import (
"time"
"next.orly.dev/pkg/acl"
"next.orly.dev/pkg/interfaces/signer/p8k"
"next.orly.dev/pkg/database"
"next.orly.dev/pkg/encoders/event"
"next.orly.dev/pkg/encoders/hex"
"next.orly.dev/pkg/encoders/tag"
"next.orly.dev/pkg/encoders/timestamp"
"next.orly.dev/pkg/interfaces/signer/p8k"
)
// testSetup creates a test database, ACL, and server
@@ -201,23 +201,24 @@ func TestUtils(t *testing.T) {
}
// Test ExtractSHA256FromPath
sha256Hex, ext, err := ExtractSHA256FromPath("abc123def456")
testHash := "abc123def456789012345678901234567890123456789012345678901234abcd"
sha256Hex, ext, err := ExtractSHA256FromPath(testHash)
if err != nil {
t.Fatalf("Failed to extract SHA256: %v", err)
}
if sha256Hex != "abc123def456" {
t.Errorf("Expected %s, got %s", "abc123def456", sha256Hex)
if sha256Hex != testHash {
t.Errorf("Expected %s, got %s", testHash, sha256Hex)
}
if ext != "" {
t.Errorf("Expected empty ext, got %s", ext)
}
sha256Hex, ext, err = ExtractSHA256FromPath("abc123def456.pdf")
sha256Hex, ext, err = ExtractSHA256FromPath(testHash + ".pdf")
if err != nil {
t.Fatalf("Failed to extract SHA256: %v", err)
}
if sha256Hex != "abc123def456" {
t.Errorf("Expected %s, got %s", "abc123def456", sha256Hex)
if sha256Hex != testHash {
t.Errorf("Expected %s, got %s", testHash, sha256Hex)
}
if ext != ".pdf" {
t.Errorf("Expected .pdf, got %s", ext)
@@ -379,4 +380,3 @@ func TestServerHandler(t *testing.T) {
t.Error("Missing CORS header")
}
}