2013-05-11 02:15:13 -04:00
|
|
|
package packer
|
|
|
|
|
2013-05-11 13:27:07 -04:00
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2013-05-11 02:15:13 -04:00
|
|
|
type TestHook struct {
|
|
|
|
runCalled bool
|
2013-05-20 19:50:35 -04:00
|
|
|
runComm Communicator
|
|
|
|
runData interface{}
|
|
|
|
runName string
|
|
|
|
runUi Ui
|
2013-05-11 02:15:13 -04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:50:25 -04:00
|
|
|
func (t *TestHook) Run(name string, ui Ui, comm Communicator, data interface{}) error {
|
2013-05-11 02:15:13 -04:00
|
|
|
t.runCalled = true
|
2013-05-12 20:30:30 -04:00
|
|
|
t.runComm = comm
|
2013-05-11 13:27:07 -04:00
|
|
|
t.runData = data
|
|
|
|
t.runName = name
|
|
|
|
t.runUi = ui
|
2013-06-26 20:50:25 -04:00
|
|
|
return nil
|
2013-05-11 13:27:07 -04:00
|
|
|
}
|
|
|
|
|
2013-05-12 20:15:03 -04: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 13:27:07 -04:00
|
|
|
func TestDispatchHook_Run_NoHooks(t *testing.T) {
|
|
|
|
// Just make sure nothing blows up
|
|
|
|
dh := &DispatchHook{make(map[string][]Hook)}
|
2013-05-12 20:30:30 -04:00
|
|
|
dh.Run("foo", nil, nil, nil)
|
2013-05-11 13:27:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDispatchHook_Run(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
hook := &TestHook{}
|
|
|
|
|
|
|
|
mapping := make(map[string][]Hook)
|
|
|
|
mapping["foo"] = []Hook{hook}
|
|
|
|
dh := &DispatchHook{mapping}
|
2013-05-12 20:30:30 -04:00
|
|
|
dh.Run("foo", nil, nil, 42)
|
2013-05-11 13:27:07 -04: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-11 02:15:13 -04:00
|
|
|
}
|