tested reactormanager except for grpc
parent
20d1cd317c
commit
4652fea1d8
@ -0,0 +1,58 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// dummyClient creates a dummy client for testing.
|
||||||
|
func dummyClient() *Client {
|
||||||
|
return &Client{
|
||||||
|
Id: rand.Int(),
|
||||||
|
Model: "dummy",
|
||||||
|
Type: "dummy",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dummyReactorManager creates a dummy reactor manager for testing.
|
||||||
|
func dummyReactorManager() (*ReactorManager, error) {
|
||||||
|
|
||||||
|
ch := make(chan error)
|
||||||
|
cl := dummyClient()
|
||||||
|
return NewReactorManager(cl, viper.New(), ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestNewReactorManager tries to create a new reactor manager.
|
||||||
|
func TestNewReactorManager(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
_, err := dummyReactorManager()
|
||||||
|
assert.Equal(err, nil, "failed to create reactor manager")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestReactorManager tries to start/stop reactor manager
|
||||||
|
func TestReactorManager(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
rm, err := dummyReactorManager()
|
||||||
|
assert.Equal(err, nil, "failed to create reactor manager")
|
||||||
|
|
||||||
|
cycles := 10
|
||||||
|
for i := 0; i < cycles; i++ {
|
||||||
|
assert.NoError(rm.Start(), "failed to start")
|
||||||
|
assert.NoError(rm.Stop(), "failed to start")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUpdateClient tries to update a reactor managers embedded client.
|
||||||
|
func TestUpdateClient(t *testing.T) {
|
||||||
|
|
||||||
|
assert := assert.New(t)
|
||||||
|
rm, err := dummyReactorManager()
|
||||||
|
assert.Equal(err, nil, "failed to create reactor manager")
|
||||||
|
|
||||||
|
cl := dummyClient()
|
||||||
|
|
||||||
|
assert.NoError(rm.UpdateClient(cl), "failed to update client")
|
||||||
|
}
|
Loading…
Reference in New Issue