diff --git a/api/service/manager_test.go b/api/service/manager_test.go index dee7facaa..8574e11df 100644 --- a/api/service/manager_test.go +++ b/api/service/manager_test.go @@ -8,7 +8,9 @@ import ( msg_pb "github.com/harmony-one/harmony/api/proto/message" ) -type SupportSyncingTest struct{} +type SupportSyncingTest struct { + msgChan chan *msg_pb.Message +} func (s *SupportSyncingTest) StartService() { fmt.Println("SupportSyncingTest starting") @@ -19,9 +21,14 @@ func (s *SupportSyncingTest) StopService() { } func (s *SupportSyncingTest) NotifyService(data map[string]interface{}) { - fmt.Println("SupportSyncingTest being notified") + t := data["test"].(*testing.T) + + if s.msgChan != data["chan"].(chan *msg_pb.Message) { + t.Error("message chan is not equal to the one from the passing params") + } } func (s *SupportSyncingTest) SetMessageChan(msgChan chan *msg_pb.Message) { + s.msgChan = msgChan } // Test TakeAction. @@ -39,3 +46,22 @@ func TestTakeAction(t *testing.T) { m.SendAction(&Action{ServiceType: Done}) } + +func TestMessageChan(t *testing.T) { + m := &Manager{} + m.SetupServiceManager() + m.RegisterService(SupportSyncing, &SupportSyncingTest{}) + msgChans := make(map[Type]chan *msg_pb.Message) + m.SetupServiceMessageChan(msgChans) + + m.SendAction(&Action{ + Action: Notify, + ServiceType: SupportSyncing, + Params: map[string]interface{}{ + "chan": msgChans[SupportSyncing], + "test": t, + }, + }) + + m.SendAction(&Action{ServiceType: Done}) +}