Fix missing context in nats test, rehabilitate cmd

This commit is contained in:
lash 2025-01-13 22:02:52 +00:00
parent aa41a606dc
commit 839ffdabac
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 11 additions and 8 deletions

View File

@ -43,8 +43,9 @@ func main() {
menuStorageService := storage.NewMenuStorageService(connData, "")
eh := viseevent.NewEventsHandler(lookup.Api)
n := nats.NewNatsSubscription(menuStorageService, eh)
eu := viseevent.NewEventsUpdater(lookup.Api, menuStorageService)
eh := eu.ToEventsHandler()
n := nats.NewNatsSubscription(eh)
err = n.Connect(ctx, config.JetstreamURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Stream connect err: %v", err)

View File

@ -46,6 +46,8 @@ func NewNatsSubscription(handler *apievent.EventsHandler) *NatsSubscription {
func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
var err error
// enables set ctx in test, even if the connstr is invalid (js msg handler doesnt take context)
n.ctx = ctx
n.conn, err = nats.Connect(connStr)
if err != nil {
return err
@ -67,7 +69,6 @@ func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error {
serverInfo := toServerInfo(n.conn)
logg.DebugCtxf(ctx, "nats connected, starting consumer", "status", n.conn.Status(), "server", serverInfo)
n.ctx = ctx
n.cctx, err = n.cs.Consume(n.handleEvent)
if err != nil {
return err

View File

@ -145,6 +145,7 @@ func TestHandleMsg(t *testing.T) {
eh := eu.ToEventsHandler()
sub := NewNatsSubscription(eh)
_ = sub.Connect(ctx, "")
data := fmt.Sprintf(`{
"block": %d,

View File

@ -34,11 +34,11 @@ func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
logg.DebugCtxf(ctx, "have event", "ev", gev)
evCC, ok := asCustodialRegistrationEvent(gev)
if ok {
return r.handler.Handle(ctx, apievent.EventTokenTransferTag, evCC)
return r.handler.Handle(ctx, apievent.EventRegistrationTag, evCC)
}
evTT, ok := asTokenTransferEvent(gev)
if ok {
return r.handler.Handle(ctx, apievent.EventRegistrationTag, evTT)
return r.handler.Handle(ctx, apievent.EventTokenTransferTag, evTT)
}
return fmt.Errorf("unexpected message")

2
go.mod
View File

@ -6,7 +6,7 @@ require (
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b
github.com/grassrootseconomics/eth-tracker v1.3.0-rc
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta

4
go.sum
View File

@ -4,8 +4,8 @@ git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7 h1:P+Bi5jcQbnCrLnKNC5k8XDTBsocyZTVifqDyZY6d0w8=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7/go.mod h1:X9aQF93xw3vcW2QftJfzLewvbotRM0U00DRtdmFw294=
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af h1:iwJ4iiF3Wbmkob++qCfj67URtdV2i6pdb9IkvmnBvQw=
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af/go.mod h1:1WryKcUnFI1J4Jl3wZJ4DX/7lnew+0PDY8xWvqc46UI=
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d h1:4nj54h7Fb/Rok6afR3wbMZPeNKKXr/1j0eYYSj/T2wk=
git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d/go.mod h1:1WryKcUnFI1J4Jl3wZJ4DX/7lnew+0PDY8xWvqc46UI=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b h1:6SieNUSEKbkjzquuwazs/lVG56zdEWF10zQQEMRJfMs=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=