You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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")
|
|
}
|