tested reactormanager except for grpc

main
KeeganForelight 1 year ago
parent 20d1cd317c
commit 4652fea1d8

@ -102,7 +102,7 @@ func (c *CentralCoordinator) ClientHandler(cl *Client) *ClientResponse {
cr.URL, cr.Org, cr.Token, cr.Bucket, err = c.Database.GetReactorClient(cl.Id)
} else {
// throw error
err = errors.New(fmt.Sprintf("Client type %s not recognized!"))
err = fmt.Errorf("Client type %s not recognized!", cl.Type)
}
// returns based on cl type
if err != nil {
@ -166,7 +166,10 @@ func (m *ReactorManagers) UpdateReactorManager(cl *Client, errCh chan error) err
if !exists {
logging.Debug(logging.DClient, "RCO creating manager for reactor client %v", cl.Id)
// creating
rm = NewReactorManager(cl, m.Config, errCh)
if rm, err = NewReactorManager(cl, m.Config, errCh); err != nil {
return err
}
// starting
if err = rm.Start(); err != nil {
return err

@ -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…
Cancel
Save