2013-05-10 23:15:13 -07:00
|
|
|
package packer
|
|
|
|
|
2013-05-11 10:27:07 -07:00
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-05-12 17:15:03 -07:00
|
|
|
func TestDispatchHook_Implements(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
var r Hook
|
|
|
|
c := &DispatchHook{nil}
|
|
|
|
|
|
|
|
assert.Implementor(c, &r, "should be a Hook")
|
|
|
|
}
|
|
|
|
|
2013-05-11 10:27:07 -07:00
|
|
|
func TestDispatchHook_Run_NoHooks(t *testing.T) {
|
|
|
|
// Just make sure nothing blows up
|
|
|
|
dh := &DispatchHook{make(map[string][]Hook)}
|
2013-05-12 17:30:30 -07:00
|
|
|
dh.Run("foo", nil, nil, nil)
|
2013-05-11 10:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDispatchHook_Run(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
2013-08-30 17:03:55 -07:00
|
|
|
hook := &MockHook{}
|
2013-05-11 10:27:07 -07:00
|
|
|
|
|
|
|
mapping := make(map[string][]Hook)
|
|
|
|
mapping["foo"] = []Hook{hook}
|
|
|
|
dh := &DispatchHook{mapping}
|
2013-05-12 17:30:30 -07:00
|
|
|
dh.Run("foo", nil, nil, 42)
|
2013-05-11 10:27:07 -07:00
|
|
|
|
2013-08-30 17:03:55 -07:00
|
|
|
assert.True(hook.RunCalled, "run should be called")
|
|
|
|
assert.Equal(hook.RunName, "foo", "should be proper event")
|
|
|
|
assert.Equal(hook.RunData, 42, "should be correct data")
|
2013-05-10 23:15:13 -07:00
|
|
|
}
|