diff --git a/backend/pkg/database/sqlite_repository_query_sql_test.go b/backend/pkg/database/sqlite_repository_query_sql_test.go index 082cd51e..51e61b6a 100644 --- a/backend/pkg/database/sqlite_repository_query_sql_test.go +++ b/backend/pkg/database/sqlite_repository_query_sql_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/fastenhealth/fasten-onprem/backend/pkg" mock_config "github.com/fastenhealth/fasten-onprem/backend/pkg/config/mock" + "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/golang/mock/gomock" "github.com/sirupsen/logrus" @@ -42,7 +43,7 @@ func (suite *RepositorySqlTestSuite) BeforeTest(suiteName, testName string) { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) suite.TestRepository = dbRepo userModel := &models.User{ diff --git a/backend/pkg/database/sqlite_repository_query_test.go b/backend/pkg/database/sqlite_repository_query_test.go index 3bf866f4..6bbb1d00 100644 --- a/backend/pkg/database/sqlite_repository_query_test.go +++ b/backend/pkg/database/sqlite_repository_query_test.go @@ -4,6 +4,7 @@ import ( "context" "github.com/fastenhealth/fasten-onprem/backend/pkg" mock_config "github.com/fastenhealth/fasten-onprem/backend/pkg/config/mock" + "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" @@ -13,7 +14,7 @@ import ( "time" ) -//mimic tests from https://hl7.org/fhir/r4/search.html#token +// mimic tests from https://hl7.org/fhir/r4/search.html#token func TestProcessSearchParameter(t *testing.T) { //setup t.Parallel() @@ -51,7 +52,7 @@ func TestProcessSearchParameter(t *testing.T) { } } -//mimic tests from https://hl7.org/fhir/r4/search.html#token +// mimic tests from https://hl7.org/fhir/r4/search.html#token func TestProcessSearchParameterValue(t *testing.T) { //setup t.Parallel() @@ -176,7 +177,7 @@ func TestSearchCodeToWhereClause(t *testing.T) { } -//TODO +// TODO func TestSearchCodeToFromClause(t *testing.T) { //setup var searchCodeToFromClauseTests = []struct { @@ -208,7 +209,7 @@ func (suite *RepositoryTestSuite) TestQueryResources_SQL() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ Username: "test_username", diff --git a/backend/pkg/database/sqlite_repository_settings_test.go b/backend/pkg/database/sqlite_repository_settings_test.go index d38a21c0..54df1625 100644 --- a/backend/pkg/database/sqlite_repository_settings_test.go +++ b/backend/pkg/database/sqlite_repository_settings_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/fastenhealth/fasten-onprem/backend/pkg" "github.com/fastenhealth/fasten-onprem/backend/pkg/config" + "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" @@ -42,7 +43,7 @@ func (suite *RepositorySettingsTestSuite) BeforeTest(suiteName, testName string) testConfig.SetDefault("log.level", "INFO") suite.TestConfig = testConfig - dbRepo, err := NewRepository(testConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(testConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) suite.TestRepository = dbRepo userModel := &models.User{ diff --git a/backend/pkg/database/sqlite_repository_test.go b/backend/pkg/database/sqlite_repository_test.go index ac996266..b2c2d0bf 100644 --- a/backend/pkg/database/sqlite_repository_test.go +++ b/backend/pkg/database/sqlite_repository_test.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/fastenhealth/fasten-onprem/backend/pkg" mock_config "github.com/fastenhealth/fasten-onprem/backend/pkg/config/mock" + "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" sourceModels "github.com/fastenhealth/fasten-sources/clients/models" "github.com/fastenhealth/gofhir-models/fhir401" @@ -74,7 +75,7 @@ func (suite *RepositoryTestSuite) TestNewRepository() { fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() //test - _, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + _, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) //assert require.NoError(suite.T(), err) @@ -85,7 +86,7 @@ func (suite *RepositoryTestSuite) TestCreateUser() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) //test @@ -105,7 +106,7 @@ func (suite *RepositoryTestSuite) TestCreateUser_WithExitingUser_ShouldFail() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) //test @@ -127,13 +128,13 @@ func (suite *RepositoryTestSuite) TestCreateUser_WithExitingUser_ShouldFail() { require.Error(suite.T(), err) } -//TODO: ensure user's cannot specify the ID when creating a user. +// TODO: ensure user's cannot specify the ID when creating a user. func (suite *RepositoryTestSuite) TestCreateUser_WithUserProvidedId_ShouldBeReplaced() { //setup fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) //test @@ -158,7 +159,7 @@ func (suite *RepositoryTestSuite) TestGetUserByUsername() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ Username: "test_username", @@ -181,7 +182,7 @@ func (suite *RepositoryTestSuite) TestGetUserByUsername_WithInvalidUsername() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ Username: "test_username", @@ -203,7 +204,7 @@ func (suite *RepositoryTestSuite) TestGetCurrentUser_WithContextBackgroundAuthUs fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ Username: "test_username", @@ -227,7 +228,7 @@ func (suite *RepositoryTestSuite) TestGetCurrentUser_WithGinContextBackgroundAut fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ Username: "test_username", @@ -255,7 +256,7 @@ func (suite *RepositoryTestSuite) TestGetCurrentUser_WithContextBackgroundAuthUs fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) //test @@ -271,7 +272,7 @@ func (suite *RepositoryTestSuite) TestCreateGlossaryEntry() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) //test @@ -306,7 +307,7 @@ func (suite *RepositoryTestSuite) TestUpsertRawResource() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -362,7 +363,7 @@ func (suite *RepositoryTestSuite) TestUpsertRawResource_WithRelatedResourceAndDu fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -409,7 +410,7 @@ func (suite *RepositoryTestSuite) TestListResources() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -511,7 +512,7 @@ func (suite *RepositoryTestSuite) TestGetResourceByResourceTypeAndId() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -564,7 +565,7 @@ func (suite *RepositoryTestSuite) TestGetResourceBySourceId() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -617,7 +618,7 @@ func (suite *RepositoryTestSuite) TestGetPatientForSources() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -673,7 +674,7 @@ func (suite *RepositoryTestSuite) TestAddResourceAssociation() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -709,7 +710,7 @@ func (suite *RepositoryTestSuite) TestAddResourceAssociation_WithMismatchingSour fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -758,7 +759,7 @@ func (suite *RepositoryTestSuite) TestRemoveResourceAssociation() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -799,7 +800,7 @@ func (suite *RepositoryTestSuite) TestGetSourceSummary() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -879,7 +880,7 @@ func (suite *RepositoryTestSuite) TestGetSummary() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -982,7 +983,7 @@ func (suite *RepositoryTestSuite) TestAddResourceComposition() { fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ @@ -1067,7 +1068,7 @@ func (suite *RepositoryTestSuite) TestAddResourceComposition_WithExistingComposi fakeConfig := mock_config.NewMockInterface(suite.MockCtrl) fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes() fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() - dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name())) + dbRepo, err := NewRepository(fakeConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) require.NoError(suite.T(), err) userModel := &models.User{ diff --git a/backend/pkg/event_bus/event_bus_test.go b/backend/pkg/event_bus/event_bus_test.go index 1e89dbbc..54029fe5 100644 --- a/backend/pkg/event_bus/event_bus_test.go +++ b/backend/pkg/event_bus/event_bus_test.go @@ -13,3 +13,12 @@ func TestEventBusInterface(t *testing.T) { //assert require.Implements(t, (*Interface)(nil), eventBusInstance, "should implement the eventBus interface") } + +func TestNoopEventBusInterface(t *testing.T) { + t.Parallel() + + noopEventBusInstance := new(noopEventBus) + + //assert + require.Implements(t, (*Interface)(nil), noopEventBusInstance, "should implement the eventBus interface") +} diff --git a/backend/pkg/event_bus/factory.go b/backend/pkg/event_bus/factory.go index 8024c77d..e2653bfc 100644 --- a/backend/pkg/event_bus/factory.go +++ b/backend/pkg/event_bus/factory.go @@ -19,3 +19,7 @@ func NewEventBusServer(logger logrus.FieldLogger) Interface { go eventBusInstance.listen() return eventBusInstance } + +func NewNoopEventBusServer() Interface { + return &noopEventBus{} +} diff --git a/backend/pkg/event_bus/mock/mock_event_bus.go b/backend/pkg/event_bus/mock/mock_event_bus.go new file mode 100644 index 00000000..a0f7cff1 --- /dev/null +++ b/backend/pkg/event_bus/mock/mock_event_bus.go @@ -0,0 +1,102 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: interface.go + +// Package mock_event_bus is a generated GoMock package. +package mock_event_bus + +import ( + reflect "reflect" + + event_bus "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" + models "github.com/fastenhealth/fasten-onprem/backend/pkg/models" + gomock "github.com/golang/mock/gomock" +) + +// MockInterface is a mock of Interface interface. +type MockInterface struct { + ctrl *gomock.Controller + recorder *MockInterfaceMockRecorder +} + +// MockInterfaceMockRecorder is the mock recorder for MockInterface. +type MockInterfaceMockRecorder struct { + mock *MockInterface +} + +// NewMockInterface creates a new mock instance. +func NewMockInterface(ctrl *gomock.Controller) *MockInterface { + mock := &MockInterface{ctrl: ctrl} + mock.recorder = &MockInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { + return m.recorder +} + +// AddListener mocks base method. +func (m *MockInterface) AddListener(listener *event_bus.EventBusListener) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddListener", listener) +} + +// AddListener indicates an expected call of AddListener. +func (mr *MockInterfaceMockRecorder) AddListener(listener interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddListener", reflect.TypeOf((*MockInterface)(nil).AddListener), listener) +} + +// PublishMessage mocks base method. +func (m *MockInterface) PublishMessage(eventMsg models.EventInterface) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PublishMessage", eventMsg) + ret0, _ := ret[0].(error) + return ret0 +} + +// PublishMessage indicates an expected call of PublishMessage. +func (mr *MockInterfaceMockRecorder) PublishMessage(eventMsg interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishMessage", reflect.TypeOf((*MockInterface)(nil).PublishMessage), eventMsg) +} + +// RemoveListener mocks base method. +func (m *MockInterface) RemoveListener(listener *event_bus.EventBusListener) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RemoveListener", listener) +} + +// RemoveListener indicates an expected call of RemoveListener. +func (mr *MockInterfaceMockRecorder) RemoveListener(listener interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveListener", reflect.TypeOf((*MockInterface)(nil).RemoveListener), listener) +} + +// TotalListenersByRoom mocks base method. +func (m *MockInterface) TotalListenersByRoom(room string) int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TotalListenersByRoom", room) + ret0, _ := ret[0].(int) + return ret0 +} + +// TotalListenersByRoom indicates an expected call of TotalListenersByRoom. +func (mr *MockInterfaceMockRecorder) TotalListenersByRoom(room interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TotalListenersByRoom", reflect.TypeOf((*MockInterface)(nil).TotalListenersByRoom), room) +} + +// TotalRooms mocks base method. +func (m *MockInterface) TotalRooms() int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TotalRooms") + ret0, _ := ret[0].(int) + return ret0 +} + +// TotalRooms indicates an expected call of TotalRooms. +func (mr *MockInterfaceMockRecorder) TotalRooms() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TotalRooms", reflect.TypeOf((*MockInterface)(nil).TotalRooms)) +} diff --git a/backend/pkg/event_bus/noop_event_bus.go b/backend/pkg/event_bus/noop_event_bus.go new file mode 100644 index 00000000..b247d8b5 --- /dev/null +++ b/backend/pkg/event_bus/noop_event_bus.go @@ -0,0 +1,12 @@ +package event_bus + +import "github.com/fastenhealth/fasten-onprem/backend/pkg/models" + +type noopEventBus struct { +} + +func (bus *noopEventBus) PublishMessage(eventMsg models.EventInterface) error { return nil } +func (bus *noopEventBus) AddListener(listener *EventBusListener) {} +func (bus *noopEventBus) RemoveListener(listener *EventBusListener) {} +func (bus *noopEventBus) TotalRooms() int { return 0 } +func (bus *noopEventBus) TotalListenersByRoom(room string) int { return 0 } diff --git a/backend/pkg/web/handler/source_test.go b/backend/pkg/web/handler/source_test.go index c3d81784..3eced2ee 100644 --- a/backend/pkg/web/handler/source_test.go +++ b/backend/pkg/web/handler/source_test.go @@ -8,6 +8,7 @@ import ( "github.com/fastenhealth/fasten-onprem/backend/pkg" mock_config "github.com/fastenhealth/fasten-onprem/backend/pkg/config/mock" "github.com/fastenhealth/fasten-onprem/backend/pkg/database" + "github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus" "github.com/fastenhealth/fasten-onprem/backend/pkg/models" "github.com/gin-gonic/gin" "github.com/golang/mock/gomock" @@ -52,7 +53,7 @@ func (suite *SourceHandlerTestSuite) BeforeTest(suiteName, testName string) { appConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes() suite.AppConfig = appConfig - appRepo, err := database.NewRepository(suite.AppConfig, logrus.WithField("test", suite.T().Name())) + appRepo, err := database.NewRepository(suite.AppConfig, logrus.WithField("test", suite.T().Name()), event_bus.NewNoopEventBusServer()) suite.AppRepository = appRepo appRepo.CreateUser(context.Background(), &models.User{