From c839ff869dade539b79dffd647afdc60fb430aac Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Fri, 27 Sep 2024 16:49:14 +0200 Subject: [PATCH] feat: completely test events COMITTED_TRANSACTIONS --- docs/events/CommittedTransactions.json | 12 +++++++----- docs/events/RevertedTransaction.json | 12 +++++++----- go.mod | 2 -- go.sum | 3 --- internal/api/v1/controllers_accounts_add_metadata.go | 3 +-- internal/machine/account.go | 3 +-- internal/machine/asset.go | 3 +-- internal/posting.go | 5 ++--- pkg/{core => }/accounts/account_test.go | 0 pkg/{core => }/accounts/accounts.go | 0 pkg/{core => }/assets/asset.go | 0 pkg/testserver/matchers.go | 5 ++++- test/e2e/integration_test.go | 3 ++- 13 files changed, 25 insertions(+), 26 deletions(-) rename pkg/{core => }/accounts/account_test.go (100%) rename pkg/{core => }/accounts/accounts.go (100%) rename pkg/{core => }/assets/asset.go (100%) diff --git a/docs/events/CommittedTransactions.json b/docs/events/CommittedTransactions.json index b03e43ea2..0ae1a2cc0 100644 --- a/docs/events/CommittedTransactions.json +++ b/docs/events/CommittedTransactions.json @@ -77,9 +77,9 @@ "type": "array" }, "Time": { - "type": "string", - "format": "date-time", - "title": "Normalized date" + "properties": {}, + "additionalProperties": false, + "type": "object" }, "Transaction": { "properties": { @@ -126,8 +126,7 @@ "postings", "metadata", "timestamp", - "id", - "revertedAt" + "id" ] }, "Volumes": { @@ -137,6 +136,9 @@ }, "output": { "$ref": "#/$defs/Int" + }, + "balance": { + "$ref": "#/$defs/Int" } }, "additionalProperties": false, diff --git a/docs/events/RevertedTransaction.json b/docs/events/RevertedTransaction.json index fef7964ed..28f788f38 100644 --- a/docs/events/RevertedTransaction.json +++ b/docs/events/RevertedTransaction.json @@ -71,9 +71,9 @@ ] }, "Time": { - "type": "string", - "format": "date-time", - "title": "Normalized date" + "properties": {}, + "additionalProperties": false, + "type": "object" }, "Transaction": { "properties": { @@ -120,8 +120,7 @@ "postings", "metadata", "timestamp", - "id", - "revertedAt" + "id" ] }, "Volumes": { @@ -131,6 +130,9 @@ }, "output": { "$ref": "#/$defs/Int" + }, + "balance": { + "$ref": "#/$defs/Int" } }, "additionalProperties": false, diff --git a/go.mod b/go.mod index 9567eb225..d8eef3686 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,6 @@ require ( github.com/onsi/gomega v1.34.2 github.com/pborman/uuid v1.2.1 github.com/pkg/errors v0.9.1 - github.com/r3labs/diff v1.1.0 github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 @@ -42,7 +41,6 @@ require ( go.uber.org/fx v1.22.2 go.uber.org/mock v0.4.0 golang.org/x/oauth2 v0.23.0 - gotest.tools/v3 v3.5.1 ) require ( diff --git a/go.sum b/go.sum index 75744d204..a103591f1 100644 --- a/go.sum +++ b/go.sum @@ -264,8 +264,6 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= -github.com/r3labs/diff v1.1.0 h1:V53xhrbTHrWFWq3gI4b94AjgEJOerO1+1l0xyHOBi8M= -github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/riandyrn/otelchi v0.10.0 h1:QMbR/FMDWBOkej6dfyWteYefUKqIFxnyrpaoWRJ9RPQ= @@ -296,7 +294,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= diff --git a/internal/api/v1/controllers_accounts_add_metadata.go b/internal/api/v1/controllers_accounts_add_metadata.go index 6f8fd8b86..3d98e9ef5 100644 --- a/internal/api/v1/controllers_accounts_add_metadata.go +++ b/internal/api/v1/controllers_accounts_add_metadata.go @@ -2,11 +2,10 @@ package v1 import ( "encoding/json" + "github.com/formancehq/ledger/pkg/accounts" "net/http" "net/url" - "github.com/formancehq/ledger/pkg/core/accounts" - "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/metadata" "github.com/formancehq/ledger/internal/api/common" diff --git a/internal/machine/account.go b/internal/machine/account.go index bf98e74b3..59a9d27e0 100644 --- a/internal/machine/account.go +++ b/internal/machine/account.go @@ -2,8 +2,7 @@ package machine import ( "fmt" - - "github.com/formancehq/ledger/pkg/core/accounts" + "github.com/formancehq/ledger/pkg/accounts" ) type AccountAddress string diff --git a/internal/machine/asset.go b/internal/machine/asset.go index ceb03ac65..2e63e64cf 100644 --- a/internal/machine/asset.go +++ b/internal/machine/asset.go @@ -2,8 +2,7 @@ package machine import ( "fmt" - - "github.com/formancehq/ledger/pkg/core/assets" + "github.com/formancehq/ledger/pkg/assets" ) type Asset string diff --git a/internal/posting.go b/internal/posting.go index 33ae71ec2..904cb84b3 100644 --- a/internal/posting.go +++ b/internal/posting.go @@ -1,11 +1,10 @@ package ledger import ( + "github.com/formancehq/ledger/pkg/accounts" + "github.com/formancehq/ledger/pkg/assets" "math/big" - "github.com/formancehq/ledger/pkg/core/accounts" - "github.com/formancehq/ledger/pkg/core/assets" - "github.com/pkg/errors" ) diff --git a/pkg/core/accounts/account_test.go b/pkg/accounts/account_test.go similarity index 100% rename from pkg/core/accounts/account_test.go rename to pkg/accounts/account_test.go diff --git a/pkg/core/accounts/accounts.go b/pkg/accounts/accounts.go similarity index 100% rename from pkg/core/accounts/accounts.go rename to pkg/accounts/accounts.go diff --git a/pkg/core/assets/asset.go b/pkg/assets/asset.go similarity index 100% rename from pkg/core/assets/asset.go rename to pkg/assets/asset.go diff --git a/pkg/testserver/matchers.go b/pkg/testserver/matchers.go index b26a05dfe..e1766ed2c 100644 --- a/pkg/testserver/matchers.go +++ b/pkg/testserver/matchers.go @@ -88,6 +88,8 @@ func (e *EventMatcher) Match(actual any) (success bool, err error) { return false, fmt.Errorf("unable to unmarshal msg: %s", err) } + Expect(ev.Type).To(Equal(e.eventName)) + rawSchema := jsonschema.Reflect(e.expected) data, err := json.Marshal(rawSchema) if err != nil { @@ -155,8 +157,9 @@ func (e *EventMatcher) NegatedFailureMessage(_ any) (message string) { var _ types.GomegaMatcher = (*EventMatcher)(nil) -func Event(expected any) types.GomegaMatcher { +func Event(eventName string, expected any) types.GomegaMatcher { return &EventMatcher{ expected: expected, + eventName: eventName, } } diff --git a/test/e2e/integration_test.go b/test/e2e/integration_test.go index b6cc8ee29..4ddcb411c 100644 --- a/test/e2e/integration_test.go +++ b/test/e2e/integration_test.go @@ -9,6 +9,7 @@ import ( "github.com/formancehq/go-libs/metadata" "github.com/formancehq/go-libs/time" "github.com/formancehq/ledger/internal/bus" + "github.com/formancehq/ledger/pkg/events" "github.com/nats-io/nats.go" "io" "math/big" @@ -144,7 +145,7 @@ var _ = Context("Ledger integration tests", func() { msgs = testServer.GetValue().Subscribe() }) It("should receive an event", func() { - Eventually(msgs).Should(Receive(Event(bus.CommittedTransactions{ + Eventually(msgs).Should(Receive(Event(events.EventTypeCommittedTransactions, bus.CommittedTransactions{ Ledger: "foo", Transactions: []ledger.Transaction{{ TransactionData: ledger.TransactionData{