github.com/moleculer-go/moleculer@v0.3.3/examples/math/math_test.go (about)

     1  package math_test
     2  
     3  import (
     4  	"github.com/moleculer-go/moleculer/broker"
     5  	test "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  
     8  	"github.com/moleculer-go/moleculer/examples/math"
     9  )
    10  
    11  var _ = test.Describe("Math", func() {
    12  
    13  	test.It("Can create a valid service definition", func() {
    14  		serviceDefinition := math.ServiceSchema()
    15  
    16  		Expect(serviceDefinition).Should(Not(BeNil()))
    17  		Expect(serviceDefinition.Name).To(Equal("math"))
    18  
    19  		Expect(serviceDefinition.Actions).Should(HaveLen(3))
    20  		Expect(serviceDefinition.Actions[0].Name).To(Equal("add"))
    21  		Expect(serviceDefinition.Actions[1].Name).To(Equal("sub"))
    22  		Expect(serviceDefinition.Actions[2].Name).To(Equal("mult"))
    23  
    24  		Expect(serviceDefinition.Events).Should(HaveLen(2))
    25  		Expect(serviceDefinition.Events[0].Name).To(Equal("math.add.called"))
    26  		Expect(serviceDefinition.Events[1].Name).To(Equal("math.sub.called"))
    27  
    28  	})
    29  
    30  	test.It("Can start broker with service and call actions", func() {
    31  		broker := broker.New()
    32  		broker.Publish(math.ServiceSchema())
    33  		broker.Start()
    34  
    35  		Expect(broker).Should(Not(BeNil()))
    36  
    37  		result := <-broker.Call("math.add", map[string]int{
    38  			"a": 1,
    39  			"b": 10,
    40  		})
    41  
    42  		Expect(result.Value()).Should(Not(BeNil()))
    43  		Expect(result.Value()).Should(Equal(11))
    44  	})
    45  })