Skip to content

Commit

Permalink
core: function DeleteEvent added to Eventer interface
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Sep 12, 2016
1 parent 3540ce7 commit 39b2ffd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion eventer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion eventer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import (
"testing"
)

func TestEventer(t *testing.T) {
func TestEventerAddEvent(t *testing.T) {
e := NewEventer()
e.AddEvent("test")

if _, ok := e.Events()["test"]; !ok {
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")
}
}

0 comments on commit 39b2ffd

Please sign in to comment.