github.com/wiselike/revel-cmd@v1.2.1/model/event_test.go (about)

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