mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-04 10:41:14 +00:00
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.
44 lines
914 B
Go
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))
|
|
}
|
|
}
|