github.com/mlmmr/revel-cmd@v0.21.2-0.20191112133115-68d8795776dd/model/event_test.go (about) 1 package model_test 2 3 import ( 4 "github.com/revel/revel" 5 "github.com/stretchr/testify/assert" 6 "testing" 7 ) 8 9 // Test that the event handler can be attached and it dispatches the event received 10 func TestEventHandler(t *testing.T) { 11 counter := 0 12 newListener := func(typeOf revel.Event, value interface{}) (responseOf revel.EventResponse) { 13 if typeOf == revel.ENGINE_SHUTDOWN_REQUEST { 14 counter++ 15 } 16 return 17 } 18 // Attach the same handler twice so we expect to see the response twice as well 19 revel.AddInitEventHandler(newListener) 20 revel.AddInitEventHandler(newListener) 21 revel.StopServer(1) 22 assert.Equal(t, counter, 2, "Expected event handler to have been called") 23 } 24