core: function DeleteEvent added to Eventer interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
3540ce7bd1
commit
39b2ffd6fd
|
@ -18,10 +18,13 @@ type eventer struct {
|
|||
type Eventer interface {
|
||||
// Events returns the map of valid Event names.
|
||||
Events() (eventnames map[string]string)
|
||||
// Event returns the map of valid Event names.
|
||||
// Event returns an event string from map of valid Event names.
|
||||
// Mostly used to validate that an Event name is valid.
|
||||
Event(name string) string
|
||||
// AddEvent registers a new Event name.
|
||||
AddEvent(name string)
|
||||
// DeleteEvent removes a previously registered Event name.
|
||||
DeleteEvent(name string)
|
||||
// Publish new events to anyone listening
|
||||
Publish(name string, data interface{})
|
||||
// Subscribe to any events from this eventer
|
||||
|
@ -67,6 +70,10 @@ func (e *eventer) AddEvent(name string) {
|
|||
e.eventnames[name] = name
|
||||
}
|
||||
|
||||
func (e *eventer) DeleteEvent(name string) {
|
||||
delete(e.eventnames, name)
|
||||
}
|
||||
|
||||
func (e *eventer) Publish(name string, data interface{}) {
|
||||
evt := NewEvent(name, data)
|
||||
e.in <- evt
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestEventer(t *testing.T) {
|
||||
func TestEventerAddEvent(t *testing.T) {
|
||||
e := NewEventer()
|
||||
e.AddEvent("test")
|
||||
|
||||
|
@ -12,3 +12,13 @@ func TestEventer(t *testing.T) {
|
|||
t.Errorf("Could not add event to list of Event names")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventerDeleteEvent(t *testing.T) {
|
||||
e := NewEventer()
|
||||
e.AddEvent("test1")
|
||||
e.DeleteEvent("test1")
|
||||
|
||||
if _, ok := e.Events()["test1"]; ok {
|
||||
t.Errorf("Could not add delete event from list of Event names")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue