2022-05-11 22:58:21 +02:00
|
|
|
package protocols
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-10-08 17:45:31 +02:00
|
|
|
"github.com/mariocandela/beelzebub/v3/parser"
|
|
|
|
"github.com/mariocandela/beelzebub/v3/tracer"
|
2022-05-11 22:58:21 +02:00
|
|
|
"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{})
|
|
|
|
|
2022-05-14 16:51:00 +02:00
|
|
|
protocolManager.SetProtocolStrategy(mockServiceStrategyValid{})
|
|
|
|
|
2022-05-11 22:58:21 +02:00
|
|
|
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{}))
|
|
|
|
}
|