From db8476693e5edf8e1879f301d9ddf257a8630d68 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 May 2022 22:58:21 +0200 Subject: [PATCH] Improve protocolManager_test.go --- protocols/protocolManager_test.go | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 protocols/protocolManager_test.go diff --git a/protocols/protocolManager_test.go b/protocols/protocolManager_test.go new file mode 100644 index 0000000..6f803f7 --- /dev/null +++ b/protocols/protocolManager_test.go @@ -0,0 +1,48 @@ +package protocols + +import ( + "beelzebub/parser" + "beelzebub/tracer" + "errors" + "github.com/stretchr/testify/assert" + "testing" +) + +type mockServiceStrategyValid struct { +} + +func (mockServiceStrategy mockServiceStrategyValid) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error { + return nil +} + +type mockServiceStrategyError struct { +} + +func (mockServiceStrategy mockServiceStrategyError) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error { + return errors.New("mockError") +} + +func TestInitServiceManager(t *testing.T) { + mockTraceStrategy := func(event tracer.Event) {} + + protocolManager := InitProtocolManager(mockTraceStrategy, mockServiceStrategyValid{}) + + assert.NotNil(t, protocolManager.strategy) + assert.NotNil(t, protocolManager.tracer) +} + +func TestInitServiceSuccess(t *testing.T) { + mockTraceStrategy := func(event tracer.Event) {} + + protocolManager := InitProtocolManager(mockTraceStrategy, mockServiceStrategyValid{}) + + assert.Nil(t, protocolManager.InitService(parser.BeelzebubServiceConfiguration{})) +} + +func TestInitServiceError(t *testing.T) { + mockTraceStrategy := func(event tracer.Event) {} + + protocolManager := InitProtocolManager(mockTraceStrategy, mockServiceStrategyError{}) + + assert.NotNil(t, protocolManager.InitService(parser.BeelzebubServiceConfiguration{})) +}