Engine: empty job names are illegal, catchall or not
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
de75af9fe2
commit
3b73c26194
2 changed files with 18 additions and 1 deletions
|
@ -122,7 +122,8 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
|||
// Catchall is shadowed by specific Register.
|
||||
if handler, exists := eng.handlers[name]; exists {
|
||||
job.handler = handler
|
||||
} else if eng.catchall != nil {
|
||||
} else if eng.catchall != nil && name != "" {
|
||||
// empty job names are illegal, catchall or not.
|
||||
job.handler = eng.catchall
|
||||
}
|
||||
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 a new issue