From 39b2ffd6fd395d04d7e049e177421e773570850e Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sun, 11 Sep 2016 13:27:43 +0200 Subject: [PATCH] core: function DeleteEvent added to Eventer interface Signed-off-by: deadprogram --- eventer.go | 9 ++++++++- eventer_test.go | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/eventer.go b/eventer.go index 67a53fb5..40b838d4 100644 --- a/eventer.go +++ b/eventer.go @@ -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 diff --git a/eventer_test.go b/eventer_test.go index 26d2ce12..28abcb06 100644 --- a/eventer_test.go +++ b/eventer_test.go @@ -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") + } +}