feat(gl): detect duplicate transaction versions
This commit is contained in:
@@ -32,6 +32,7 @@ func Run(ctx context.Context, repository Repository, pageSize int) (Report, erro
|
|||||||
pageSize = 100
|
pageSize = 100
|
||||||
}
|
}
|
||||||
report := Report{Invalid: make([]Issue, 0)}
|
report := Report{Invalid: make([]Issue, 0)}
|
||||||
|
seen := make(map[string]string)
|
||||||
for offset := 0; ; offset += pageSize {
|
for offset := 0; ; offset += pageSize {
|
||||||
journals, err := repository.List(ctx, ledger.JournalFilter{Limit: pageSize, Offset: offset})
|
journals, err := repository.List(ctx, ledger.JournalFilter{Limit: pageSize, Offset: offset})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -43,6 +44,12 @@ func Run(ctx context.Context, repository Repository, pageSize int) (Report, erro
|
|||||||
report.Invalid = append(report.Invalid, Issue{JournalID: journal.ID, Error: err.Error()})
|
report.Invalid = append(report.Invalid, Issue{JournalID: journal.ID, Error: err.Error()})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
key := journal.SourceService + "\x00" + journal.SourceTransactionID + "\x00" + fmt.Sprint(journal.EventVersion)
|
||||||
|
if previous, exists := seen[key]; exists {
|
||||||
|
report.Invalid = append(report.Invalid, Issue{JournalID: journal.ID, Error: fmt.Sprintf("duplicate source transaction/version; first journal %s", previous)})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[key] = journal.ID
|
||||||
report.Valid++
|
report.Valid++
|
||||||
}
|
}
|
||||||
if len(journals) < pageSize {
|
if len(journals) < pageSize {
|
||||||
|
|||||||
@@ -41,3 +41,16 @@ func TestRunScansAndReportsInvalidJournals(t *testing.T) {
|
|||||||
t.Fatalf("unexpected report: %+v", report)
|
t.Fatalf("unexpected report: %+v", report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunReportsDuplicateTransactionVersions(t *testing.T) {
|
||||||
|
first := validJournal()
|
||||||
|
second := validJournal()
|
||||||
|
second.ID = "j2"
|
||||||
|
report, err := Run(context.Background(), repositoryStub{pages: [][]ledger.Journal{{first, second}}}, 10)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.Valid != 1 || len(report.Invalid) != 1 {
|
||||||
|
t.Fatalf("unexpected report: %+v", report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user