mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Improve protocolManager_test.go
This commit is contained in:
48
protocols/protocolManager_test.go
Normal file
48
protocols/protocolManager_test.go
Normal file
@ -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{}))
|
||||||
|
}
|
Reference in New Issue
Block a user