mirror of https://github.com/docker/docs.git
Merge pull request #5538 from shykes/pr_out_engine_catchall_handler_is_shadowed_by_specific_handlers
This commit is contained in:
commit
7c3a06634b
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue