示例#1
0
func SetupHealthTest(t *testing.T) {
	mockHealthDeps = &HealthTestDependencies{}
	HealthHandlerDependencies = &HealthDependencies{}

	statsDMock := &mocks.MockStatsD{}

	_ = global.SetupInjection(
		&inject.Object{Value: HealthHandlerDependencies},
		&inject.Object{Value: mockHealthDeps},
		&inject.Object{Value: log.New(os.Stdout, "tester", log.Lshortfile)},
		&inject.Object{Value: statsDMock, Name: "statsd"},
	)

	mockHealthDeps.StatsMock.Mock.On("Increment", mock.Anything).Return()
}
示例#2
0
func SetupEventTest(t *testing.T) {
	EventHandlerDependencies = &EventDependencies{}
	mockEventDeps = &EventTestDependencies{}

	statsDMock := &mocks.MockStatsD{}
	queueMock := &mocks.MockQueue{}

	_ = global.SetupInjection(
		&inject.Object{Value: EventHandlerDependencies},
		&inject.Object{Value: mockEventDeps},
		&inject.Object{Value: log.New(os.Stdout, "tester", log.Lshortfile)},
		&inject.Object{Value: statsDMock, Name: "statsd"},
		&inject.Object{Value: queueMock, Name: "eventqueue"},
	)

	mockEventDeps.StatsMock.Mock.On("Increment", mock.Anything).Return()
	mockEventDeps.QueueMock.Mock.On("Add", mock.Anything, mock.Anything).Return(nil)
}
示例#3
0
func SetupRegisterTest(t *testing.T) {
	RegisterHandlerDependencies = &RegisterDependencies{}
	mockRegisterDeps = &RegisterTestDependencies{}

	statsDMock := &mocks.MockStatsD{}
	dalMock := &mocks.MockDal{}

	_ = global.SetupInjection(
		&inject.Object{Value: RegisterHandlerDependencies},
		&inject.Object{Value: mockRegisterDeps},
		&inject.Object{Value: log.New(os.Stdout, "tester", log.Lshortfile)},
		&inject.Object{Value: statsDMock, Name: "statsd"},
		&inject.Object{Value: dalMock, Name: "dal"},
	)

	mockRegisterDeps.StatsMock.Mock.On("Increment", mock.Anything).Return()
	mockRegisterDeps.DalMock.Mock.On("UpsertRegistration", mock.Anything).Return(nil, nil)
	mockRegisterDeps.DalMock.Mock.On("DeleteRegistration", mock.Anything).Return(nil, nil)
}
示例#4
0
func setupInjection() {
	err := global.SetupInjection(
		&inject.Object{Value: handlers.HealthHandlerDependencies},
		&inject.Object{Value: handlers.RegisterHandlerDependencies},
		&inject.Object{Value: handlers.EventHandlerDependencies},
		&inject.Object{Value: ClientDeps},
		&inject.Object{Value: createLogger()},
		&inject.Object{Value: createStatsDClient(), Name: "statsd"},
		&inject.Object{Value: createMongoClient(), Name: "dal"},
		&inject.Object{Value: createEventQueueClient(), Name: "eventqueue"},
		&inject.Object{Value: createDeadLetterQueueClient(), Name: "deadletterqueue"},
		&inject.Object{Value: createEventDispatcher(), Name: "eventdispatcher"},
		&inject.Object{Value: createEventQueueWorkerFactory(), Name: "eventqueueworkerfactory"},
		&inject.Object{Value: createDeadLetterQueueWorkerFactory(), Name: "deadletterqueueworkerfactory"},
	)

	if err != nil {
		panic(fmt.Sprintln("Unable to create injection framework: ", err))
	}

}
示例#5
0
func SetupClientTest(t *testing.T) {
	ClientDeps = &ClientDependencies{}
	mockClientDeps = &ClientTestDependencies{}

	statsDMock := &mocks.MockStatsD{}
	eventQueueMock := &mocks.MockQueue{}
	deadLetterQueueMock := &mocks.MockQueue{}
	mockEventWorkerFactory := &MockWorkerFactory{}
	mockDeadLetterWorkerFactory := &MockWorkerFactory{}
	mockWorker = &mocks.MockWorker{}
	mockDeadLetterWorker = &mocks.MockWorker{}

	global.Config.RetryIntervals = []string{"10s"}

	testWaitGroup = sync.WaitGroup{}
	testWaitGroup.Add(1)

	_ = global.SetupInjection(
		&inject.Object{Value: ClientDeps},
		&inject.Object{Value: mockClientDeps},
		&inject.Object{Value: statsDMock, Name: "statsd"},
		&inject.Object{Value: log.New(os.Stdout, "Testing: ", log.Lshortfile)},
		&inject.Object{Value: eventQueueMock, Name: "eventqueue"},
		&inject.Object{Value: deadLetterQueueMock, Name: "deadletterqueue"},
		&inject.Object{Value: mockEventWorkerFactory, Name: "eventqueueworkerfactory"},
		&inject.Object{Value: mockDeadLetterWorkerFactory, Name: "deadletterqueueworkerfactory"},
	)

	mockClientDeps.StatsMock.Mock.On("Increment", mock.Anything).Return()
	mockClientDeps.EventQueueMock.Mock.On("StartConsuming", mock.Anything, mock.Anything, mock.Anything)
	mockClientDeps.EventWorkerFactoryMock.Mock.On("Create").Return(mockWorker)
	mockWorker.Mock.On("HandleItem", mock.Anything, mock.Anything).Return(nil)

	mockClientDeps.DeadLetterQueueMock.Mock.On("StartConsuming", mock.Anything, mock.Anything, mock.Anything)
	mockClientDeps.DeadLetterWorkerFactoryMock.Mock.On("Create").Return(mockDeadLetterWorker)
	mockDeadLetterWorker.Mock.On("HandleItem", mock.Anything, mock.Anything).Return(nil)
}