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 <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-04-23 11:54:35 -07:00
parent 87e8d7754e
commit 7100ace42b
7 changed files with 21 additions and 42 deletions

View file

@ -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()

View file

@ -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

View file

@ -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 {

View file

@ -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 {

View file

@ -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...)
}

View file

@ -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")

View file

@ -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)