github.com/moleculer-go/moleculer@v0.3.3/test/broker_mock.go (about)

     1  package test
     2  
     3  import (
     4  	bus "github.com/moleculer-go/goemitter"
     5  	"github.com/moleculer-go/moleculer"
     6  	log "github.com/sirupsen/logrus"
     7  )
     8  
     9  var logger = log.WithField("unit test", "<root>")
    10  
    11  func Logger(name string, value string) *log.Entry {
    12  	return logger.WithField(name, value)
    13  }
    14  
    15  func DelegatesWithId(nodeID string) *moleculer.BrokerDelegates {
    16  	return DelegatesWithIdAndConfig(nodeID, moleculer.Config{})
    17  }
    18  
    19  func DelegatesWithIdAndConfig(nodeID string, config moleculer.Config) *moleculer.BrokerDelegates {
    20  	localBus := bus.Construct()
    21  	localNode := NodeMock{ID: nodeID}
    22  	broker := &moleculer.BrokerDelegates{
    23  		LocalNode: func() moleculer.Node {
    24  			return &localNode
    25  		},
    26  		Logger: Logger,
    27  		Bus: func() *bus.Emitter {
    28  			return localBus
    29  		},
    30  		Config: config,
    31  	}
    32  	return broker
    33  }
    34  
    35  // func ContextAndDelegated(nodeID string, config moleculer.Config) (moleculer.BrokerContext, *moleculer.BrokerDelegates) {
    36  // 	dl := DelegatesWithIdAndConfig(nodeID, config)
    37  // 	ctx := context.BrokerContext(dl)
    38  // 	return ctx, dl
    39  // }