github.com/moleculer-go/moleculer@v0.3.3/registry/eventCatalog_test.go (about)

     1  package registry_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/moleculer-go/moleculer/test"
     7  
     8  	"github.com/moleculer-go/moleculer"
     9  	"github.com/moleculer-go/moleculer/registry"
    10  	"github.com/moleculer-go/moleculer/service"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  	log "github.com/sirupsen/logrus"
    14  )
    15  
    16  var _ = Describe("Event Catalog", func() {
    17  	handler := func(ctx moleculer.Context, params moleculer.Payload) {
    18  		fmt.Println("params: ", params)
    19  	}
    20  	It("Should add events and find them using Next()", func() {
    21  
    22  		catalog := registry.CreateEventCatalog(log.New().WithField("catalog", "events"))
    23  
    24  		srv := service.FromSchema(moleculer.ServiceSchema{
    25  			Name: "x",
    26  			Events: []moleculer.Event{
    27  				moleculer.Event{
    28  					Name:    "user.added",
    29  					Handler: handler,
    30  				},
    31  			},
    32  		}, test.DelegatesWithId("node-test-1"))
    33  		srv.SetNodeID("node-test-1")
    34  		catalog.Add(srv.Events()[0], srv, true)
    35  		Expect(catalog).ShouldNot(BeNil())
    36  	})
    37  })