Merge pull request #5538 from shykes/pr_out_engine_catchall_handler_is_shadowed_by_specific_handlers

This commit is contained in:
Victor Vieux 2014-05-05 13:48:11 -07:00
commit 7c3a06634b
2 changed files with 22 additions and 6 deletions

View File

@ -118,13 +118,13 @@ func (eng *Engine) Job(name string, args ...string) *Job {
if eng.Logging {
job.Stderr.Add(utils.NopWriteCloser(eng.Stderr))
}
if eng.catchall != nil {
// Catchall is shadowed by specific Register.
if handler, exists := eng.handlers[name]; exists {
job.handler = handler
} else if eng.catchall != nil && name != "" {
// empty job names are illegal, catchall or not.
job.handler = eng.catchall
} else {
handler, exists := eng.handlers[name]
if exists {
job.handler = handler
}
}
return job
}

View File

@ -133,3 +133,19 @@ func TestParseJob(t *testing.T) {
t.Fatalf("Job was not called")
}
}
func TestCatchallEmptyName(t *testing.T) {
eng := New()
var called bool
eng.RegisterCatchall(func(job *Job) Status {
called = true
return StatusOK
})
err := eng.Job("").Run()
if err == nil {
t.Fatalf("Engine.Job(\"\").Run() should return an error")
}
if called {
t.Fatalf("Engine.Job(\"\").Run() should return an error")
}
}