Files
weave-scope/probe/controls/controls_test.go
Krzesimir Nowak 41193b428e Make control handlers registry an object and extend its functionality
It is not a singleton anymore. Instead it is an object with a registry
backend. The default registry backend is provided, which is equivalent
to what used to be before. Custom backend can be provided for testing
purposes.

The registry also supports batch operations to remove and add handlers
as an atomic step.
2016-08-12 17:03:42 +02:00

44 lines
914 B
Go

package controls_test
import (
"reflect"
"testing"
"github.com/weaveworks/scope/common/xfer"
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/test"
)
func TestControls(t *testing.T) {
registry := controls.NewDefaultHandlerRegistry()
registry.Register("foo", func(req xfer.Request) xfer.Response {
return xfer.Response{
Value: "bar",
}
})
defer registry.Rm("foo")
want := xfer.Response{
Value: "bar",
}
have := registry.HandleControlRequest(xfer.Request{
Control: "foo",
})
if !reflect.DeepEqual(want, have) {
t.Fatal(test.Diff(want, have))
}
}
func TestControlsNotFound(t *testing.T) {
registry := controls.NewDefaultHandlerRegistry()
want := xfer.Response{
Error: "Control \"baz\" not recognised",
}
have := registry.HandleControlRequest(xfer.Request{
Control: "baz",
})
if !reflect.DeepEqual(want, have) {
t.Fatal(test.Diff(want, have))
}
}