feat(backend): add transactional outbox and embedded goose migrations
This commit is contained in:
1 parent
653f3775f8
commit
15e2e50561
40 files changed
+2471
-67
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
func TestMapOutboxErrorRecognizesOutboxConflicts(t *testing.T) {
|
||||
for _, constraint := range []string{outboxPrimaryKeyConstraint, outboxAggregateVersionConstraint} {
|
||||
err := mapOutboxError(&pgconn.PgError{Code: uniqueViolationCode, ConstraintName: constraint})
|
||||
if !errors.Is(err, outbound.ErrOutboxEventConflict) {
|
||||
t.Fatalf("mapOutboxError(%s) = %v, want ErrOutboxEventConflict", constraint, err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), constraint) {
|
||||
t.Fatalf("mapOutboxError(%s) = %v, want the constraint name in the message", constraint, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapOutboxErrorKeepsOtherErrors(t *testing.T) {
|
||||
tests := []error{
|
||||
&pgconn.PgError{Code: uniqueViolationCode, ConstraintName: "other_table_key"},
|
||||
&pgconn.PgError{Code: "23514", ConstraintName: "outbox_events_schema_version_positive"},
|
||||
errors.New("connection reset"),
|
||||
}
|
||||
for _, original := range tests {
|
||||
if err := mapOutboxError(original); err != original { //nolint:errorlint // Identity is the property under test.
|
||||
t.Fatalf("mapOutboxError(%v) = %v, want the original error", original, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendRejectsZeroValueEventBeforeTheDatabase(t *testing.T) {
|
||||
// A nil query set proves that validation happens before any statement.
|
||||
err := outboxWriter{}.Append(t.Context(), domain.DomainEvent{})
|
||||
if !errors.Is(err, domain.ErrInvalidDomainEvent) {
|
||||
t.Fatalf("Append() error = %v, want ErrInvalidDomainEvent", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user