Engine: cleanup side effects between tests

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-02-24 12:26:56 -08:00
Родитель f14f4aa509
Коммит 62b21daded
2 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -29,6 +29,10 @@ func Register(name string, handler Handler) error {
return nil return nil
} }
func unregister(name string) {
delete(globalHandlers, name)
}
// The Engine is the core of Docker. // The Engine is the core of Docker.
// It acts as a store for *containers*, and allows manipulation of these // It acts as a store for *containers*, and allows manipulation of these
// containers by executing *jobs*. // containers by executing *jobs*.

Просмотреть файл

@ -16,6 +16,8 @@ func TestRegister(t *testing.T) {
if err := Register("dummy1", nil); err == nil { if err := Register("dummy1", nil); err == nil {
t.Fatalf("Expecting error, got none") t.Fatalf("Expecting error, got none")
} }
// Register is global so let's cleanup to avoid conflicts
defer unregister("dummy1")
eng := newTestEngine(t) eng := newTestEngine(t)
@ -32,6 +34,7 @@ func TestRegister(t *testing.T) {
if err := eng.Register("dummy2", nil); err == nil { if err := eng.Register("dummy2", nil); err == nil {
t.Fatalf("Expecting error, got none") t.Fatalf("Expecting error, got none")
} }
defer unregister("dummy2")
} }
func TestJob(t *testing.T) { func TestJob(t *testing.T) {
@ -48,6 +51,7 @@ func TestJob(t *testing.T) {
} }
eng.Register("dummy2", h) eng.Register("dummy2", h)
defer unregister("dummy2")
job2 := eng.Job("dummy2", "--level=awesome") job2 := eng.Job("dummy2", "--level=awesome")
if job2.handler == nil { if job2.handler == nil {