From 7100ace42bda2660d1eaecb2ec096ba6753688ea Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 23 Apr 2014 11:54:35 -0700 Subject: [PATCH] Remove error from engine.New() Without creating a root there is no way for the engine to return an error from the new function. Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- api/server/server_unit_test.go | 12 ++---------- docker/docker.go | 7 ++----- engine/engine.go | 4 ++-- engine/engine_test.go | 14 +++++++------- engine/helpers_test.go | 10 +--------- engine/job_test.go | 10 +++++----- integration/utils_test.go | 6 ++---- 7 files changed, 21 insertions(+), 42 deletions(-) diff --git a/api/server/server_unit_test.go b/api/server/server_unit_test.go index 2dcd0df790..8ab34127ac 100644 --- a/api/server/server_unit_test.go +++ b/api/server/server_unit_test.go @@ -57,7 +57,7 @@ func TesthttpError(t *testing.T) { } func TestGetVersion(t *testing.T) { - eng := tmpEngine(t) + eng := engine.New() var called bool eng.Register("version", func(job *engine.Job) engine.Status { called = true @@ -86,7 +86,7 @@ func TestGetVersion(t *testing.T) { } func TestGetInfo(t *testing.T) { - eng := tmpEngine(t) + eng := engine.New() var called bool eng.Register("info", func(job *engine.Job) engine.Status { called = true @@ -126,14 +126,6 @@ func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t * return r } -func tmpEngine(t *testing.T) *engine.Engine { - eng, err := engine.New() - if err != nil { - t.Fatal(err) - } - return eng -} - func readEnv(src io.Reader, t *testing.T) *engine.Env { out := engine.NewOutput() v, err := out.AddEnv() diff --git a/docker/docker.go b/docker/docker.go index aed3b0778d..7a4ddc72a5 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -121,14 +121,11 @@ func main() { log.Fatalf("Unable to get the full path to root (%s): %s", root, err) } } - if err := checkKernelAndArch(); err != nil { log.Fatal(err) } - eng, err := engine.New() - if err != nil { - log.Fatal(err) - } + + eng := engine.New() // Load builtins builtins.Register(eng) // load the daemon in the background so we can immediately start diff --git a/engine/engine.go b/engine/engine.go index 9cc1bd5004..58c37ab933 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -54,7 +54,7 @@ func (eng *Engine) Register(name string, handler Handler) error { } // New initializes a new engine. -func New() (*Engine, error) { +func New() *Engine { eng := &Engine{ handlers: make(map[string]Handler), id: utils.RandomString(), @@ -73,7 +73,7 @@ func New() (*Engine, error) { for k, v := range globalHandlers { eng.handlers[k] = v } - return eng, nil + return eng } func (eng *Engine) String() string { diff --git a/engine/engine_test.go b/engine/engine_test.go index 63c4660eb1..8023bd58f3 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -17,7 +17,7 @@ func TestRegister(t *testing.T) { // Register is global so let's cleanup to avoid conflicts defer unregister("dummy1") - eng := newTestEngine(t) + eng := New() //Should fail because global handlers are copied //at the engine creation @@ -36,7 +36,7 @@ func TestRegister(t *testing.T) { } func TestJob(t *testing.T) { - eng := newTestEngine(t) + eng := New() job1 := eng.Job("dummy1", "--level=awesome") if job1.handler != nil { @@ -62,7 +62,7 @@ func TestJob(t *testing.T) { } func TestEngineCommands(t *testing.T) { - eng := newTestEngine(t) + eng := New() handler := func(job *Job) Status { return StatusOK } eng.Register("foo", handler) eng.Register("bar", handler) @@ -79,8 +79,8 @@ func TestEngineCommands(t *testing.T) { } func TestEngineString(t *testing.T) { - eng1 := newTestEngine(t) - eng2 := newTestEngine(t) + eng1 := New() + eng2 := New() s1 := eng1.String() s2 := eng2.String() if eng1 == eng2 { @@ -89,7 +89,7 @@ func TestEngineString(t *testing.T) { } func TestEngineLogf(t *testing.T) { - eng := newTestEngine(t) + eng := New() input := "Test log line" if n, err := eng.Logf("%s\n", input); err != nil { t.Fatal(err) @@ -99,7 +99,7 @@ func TestEngineLogf(t *testing.T) { } func TestParseJob(t *testing.T) { - eng := newTestEngine(t) + eng := New() // Verify that the resulting job calls to the right place var called bool eng.Register("echo", func(job *Job) Status { diff --git a/engine/helpers_test.go b/engine/helpers_test.go index a8d3dfc4d4..cfa11da7cd 100644 --- a/engine/helpers_test.go +++ b/engine/helpers_test.go @@ -6,14 +6,6 @@ import ( var globalTestID string -func newTestEngine(t *testing.T) *Engine { - eng, err := New() - if err != nil { - t.Fatal(err) - } - return eng -} - func mkJob(t *testing.T, name string, args ...string) *Job { - return newTestEngine(t).Job(name, args...) + return New().Job(name, args...) } diff --git a/engine/job_test.go b/engine/job_test.go index ace398f934..1f927cbafc 100644 --- a/engine/job_test.go +++ b/engine/job_test.go @@ -5,7 +5,7 @@ import ( ) func TestJobStatusOK(t *testing.T) { - eng := newTestEngine(t) + eng := New() eng.Register("return_ok", func(job *Job) Status { return StatusOK }) err := eng.Job("return_ok").Run() if err != nil { @@ -14,7 +14,7 @@ func TestJobStatusOK(t *testing.T) { } func TestJobStatusErr(t *testing.T) { - eng := newTestEngine(t) + eng := New() eng.Register("return_err", func(job *Job) Status { return StatusErr }) err := eng.Job("return_err").Run() if err == nil { @@ -23,7 +23,7 @@ func TestJobStatusErr(t *testing.T) { } func TestJobStatusNotFound(t *testing.T) { - eng := newTestEngine(t) + eng := New() eng.Register("return_not_found", func(job *Job) Status { return StatusNotFound }) err := eng.Job("return_not_found").Run() if err == nil { @@ -32,7 +32,7 @@ func TestJobStatusNotFound(t *testing.T) { } func TestJobStdoutString(t *testing.T) { - eng := newTestEngine(t) + eng := New() // FIXME: test multiple combinations of output and status eng.Register("say_something_in_stdout", func(job *Job) Status { job.Printf("Hello world\n") @@ -53,7 +53,7 @@ func TestJobStdoutString(t *testing.T) { } func TestJobStderrString(t *testing.T) { - eng := newTestEngine(t) + eng := New() // FIXME: test multiple combinations of output and status eng.Register("say_something_in_stderr", func(job *Job) Status { job.Errorf("Warning, something might happen\nHere it comes!\nOh no...\nSomething happened\n") diff --git a/integration/utils_test.go b/integration/utils_test.go index f455657705..6901662ce6 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -182,10 +182,8 @@ func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engin } } os.MkdirAll(root, 0700) - eng, err := engine.New() - if err != nil { - t.Fatal(err) - } + + eng := engine.New() // Load default plugins builtins.Register(eng) // (This is manually copied and modified from main() until we have a more generic plugin system)