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)
| ... | ... |
@@ -57,7 +57,7 @@ func TesthttpError(t *testing.T) {
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
func TestGetVersion(t *testing.T) {
|
| 60 |
- eng := tmpEngine(t) |
|
| 60 |
+ eng := engine.New() |
|
| 61 | 61 |
var called bool |
| 62 | 62 |
eng.Register("version", func(job *engine.Job) engine.Status {
|
| 63 | 63 |
called = true |
| ... | ... |
@@ -86,7 +86,7 @@ func TestGetVersion(t *testing.T) {
|
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 | 88 |
func TestGetInfo(t *testing.T) {
|
| 89 |
- eng := tmpEngine(t) |
|
| 89 |
+ eng := engine.New() |
|
| 90 | 90 |
var called bool |
| 91 | 91 |
eng.Register("info", func(job *engine.Job) engine.Status {
|
| 92 | 92 |
called = true |
| ... | ... |
@@ -126,14 +126,6 @@ func serveRequest(method, target string, body io.Reader, eng *engine.Engine, t * |
| 126 | 126 |
return r |
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 |
-func tmpEngine(t *testing.T) *engine.Engine {
|
|
| 130 |
- eng, err := engine.New() |
|
| 131 |
- if err != nil {
|
|
| 132 |
- t.Fatal(err) |
|
| 133 |
- } |
|
| 134 |
- return eng |
|
| 135 |
-} |
|
| 136 |
- |
|
| 137 | 129 |
func readEnv(src io.Reader, t *testing.T) *engine.Env {
|
| 138 | 130 |
out := engine.NewOutput() |
| 139 | 131 |
v, err := out.AddEnv() |
| ... | ... |
@@ -121,14 +121,11 @@ func main() {
|
| 121 | 121 |
log.Fatalf("Unable to get the full path to root (%s): %s", root, err)
|
| 122 | 122 |
} |
| 123 | 123 |
} |
| 124 |
- |
|
| 125 | 124 |
if err := checkKernelAndArch(); err != nil {
|
| 126 | 125 |
log.Fatal(err) |
| 127 | 126 |
} |
| 128 |
- eng, err := engine.New() |
|
| 129 |
- if err != nil {
|
|
| 130 |
- log.Fatal(err) |
|
| 131 |
- } |
|
| 127 |
+ |
|
| 128 |
+ eng := engine.New() |
|
| 132 | 129 |
// Load builtins |
| 133 | 130 |
builtins.Register(eng) |
| 134 | 131 |
// load the daemon in the background so we can immediately start |
| ... | ... |
@@ -54,7 +54,7 @@ func (eng *Engine) Register(name string, handler Handler) error {
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
// New initializes a new engine. |
| 57 |
-func New() (*Engine, error) {
|
|
| 57 |
+func New() *Engine {
|
|
| 58 | 58 |
eng := &Engine{
|
| 59 | 59 |
handlers: make(map[string]Handler), |
| 60 | 60 |
id: utils.RandomString(), |
| ... | ... |
@@ -73,7 +73,7 @@ func New() (*Engine, error) {
|
| 73 | 73 |
for k, v := range globalHandlers {
|
| 74 | 74 |
eng.handlers[k] = v |
| 75 | 75 |
} |
| 76 |
- return eng, nil |
|
| 76 |
+ return eng |
|
| 77 | 77 |
} |
| 78 | 78 |
|
| 79 | 79 |
func (eng *Engine) String() string {
|
| ... | ... |
@@ -17,7 +17,7 @@ func TestRegister(t *testing.T) {
|
| 17 | 17 |
// Register is global so let's cleanup to avoid conflicts |
| 18 | 18 |
defer unregister("dummy1")
|
| 19 | 19 |
|
| 20 |
- eng := newTestEngine(t) |
|
| 20 |
+ eng := New() |
|
| 21 | 21 |
|
| 22 | 22 |
//Should fail because global handlers are copied |
| 23 | 23 |
//at the engine creation |
| ... | ... |
@@ -36,7 +36,7 @@ func TestRegister(t *testing.T) {
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
func TestJob(t *testing.T) {
|
| 39 |
- eng := newTestEngine(t) |
|
| 39 |
+ eng := New() |
|
| 40 | 40 |
job1 := eng.Job("dummy1", "--level=awesome")
|
| 41 | 41 |
|
| 42 | 42 |
if job1.handler != nil {
|
| ... | ... |
@@ -62,7 +62,7 @@ func TestJob(t *testing.T) {
|
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
func TestEngineCommands(t *testing.T) {
|
| 65 |
- eng := newTestEngine(t) |
|
| 65 |
+ eng := New() |
|
| 66 | 66 |
handler := func(job *Job) Status { return StatusOK }
|
| 67 | 67 |
eng.Register("foo", handler)
|
| 68 | 68 |
eng.Register("bar", handler)
|
| ... | ... |
@@ -79,8 +79,8 @@ func TestEngineCommands(t *testing.T) {
|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
func TestEngineString(t *testing.T) {
|
| 82 |
- eng1 := newTestEngine(t) |
|
| 83 |
- eng2 := newTestEngine(t) |
|
| 82 |
+ eng1 := New() |
|
| 83 |
+ eng2 := New() |
|
| 84 | 84 |
s1 := eng1.String() |
| 85 | 85 |
s2 := eng2.String() |
| 86 | 86 |
if eng1 == eng2 {
|
| ... | ... |
@@ -89,7 +89,7 @@ func TestEngineString(t *testing.T) {
|
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 | 91 |
func TestEngineLogf(t *testing.T) {
|
| 92 |
- eng := newTestEngine(t) |
|
| 92 |
+ eng := New() |
|
| 93 | 93 |
input := "Test log line" |
| 94 | 94 |
if n, err := eng.Logf("%s\n", input); err != nil {
|
| 95 | 95 |
t.Fatal(err) |
| ... | ... |
@@ -99,7 +99,7 @@ func TestEngineLogf(t *testing.T) {
|
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
func TestParseJob(t *testing.T) {
|
| 102 |
- eng := newTestEngine(t) |
|
| 102 |
+ eng := New() |
|
| 103 | 103 |
// Verify that the resulting job calls to the right place |
| 104 | 104 |
var called bool |
| 105 | 105 |
eng.Register("echo", func(job *Job) Status {
|
| ... | ... |
@@ -6,14 +6,6 @@ import ( |
| 6 | 6 |
|
| 7 | 7 |
var globalTestID string |
| 8 | 8 |
|
| 9 |
-func newTestEngine(t *testing.T) *Engine {
|
|
| 10 |
- eng, err := New() |
|
| 11 |
- if err != nil {
|
|
| 12 |
- t.Fatal(err) |
|
| 13 |
- } |
|
| 14 |
- return eng |
|
| 15 |
-} |
|
| 16 |
- |
|
| 17 | 9 |
func mkJob(t *testing.T, name string, args ...string) *Job {
|
| 18 |
- return newTestEngine(t).Job(name, args...) |
|
| 10 |
+ return New().Job(name, args...) |
|
| 19 | 11 |
} |
| ... | ... |
@@ -5,7 +5,7 @@ import ( |
| 5 | 5 |
) |
| 6 | 6 |
|
| 7 | 7 |
func TestJobStatusOK(t *testing.T) {
|
| 8 |
- eng := newTestEngine(t) |
|
| 8 |
+ eng := New() |
|
| 9 | 9 |
eng.Register("return_ok", func(job *Job) Status { return StatusOK })
|
| 10 | 10 |
err := eng.Job("return_ok").Run()
|
| 11 | 11 |
if err != nil {
|
| ... | ... |
@@ -14,7 +14,7 @@ func TestJobStatusOK(t *testing.T) {
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 | 16 |
func TestJobStatusErr(t *testing.T) {
|
| 17 |
- eng := newTestEngine(t) |
|
| 17 |
+ eng := New() |
|
| 18 | 18 |
eng.Register("return_err", func(job *Job) Status { return StatusErr })
|
| 19 | 19 |
err := eng.Job("return_err").Run()
|
| 20 | 20 |
if err == nil {
|
| ... | ... |
@@ -23,7 +23,7 @@ func TestJobStatusErr(t *testing.T) {
|
| 23 | 23 |
} |
| 24 | 24 |
|
| 25 | 25 |
func TestJobStatusNotFound(t *testing.T) {
|
| 26 |
- eng := newTestEngine(t) |
|
| 26 |
+ eng := New() |
|
| 27 | 27 |
eng.Register("return_not_found", func(job *Job) Status { return StatusNotFound })
|
| 28 | 28 |
err := eng.Job("return_not_found").Run()
|
| 29 | 29 |
if err == nil {
|
| ... | ... |
@@ -32,7 +32,7 @@ func TestJobStatusNotFound(t *testing.T) {
|
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 | 34 |
func TestJobStdoutString(t *testing.T) {
|
| 35 |
- eng := newTestEngine(t) |
|
| 35 |
+ eng := New() |
|
| 36 | 36 |
// FIXME: test multiple combinations of output and status |
| 37 | 37 |
eng.Register("say_something_in_stdout", func(job *Job) Status {
|
| 38 | 38 |
job.Printf("Hello world\n")
|
| ... | ... |
@@ -53,7 +53,7 @@ func TestJobStdoutString(t *testing.T) {
|
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 | 55 |
func TestJobStderrString(t *testing.T) {
|
| 56 |
- eng := newTestEngine(t) |
|
| 56 |
+ eng := New() |
|
| 57 | 57 |
// FIXME: test multiple combinations of output and status |
| 58 | 58 |
eng.Register("say_something_in_stderr", func(job *Job) Status {
|
| 59 | 59 |
job.Errorf("Warning, something might happen\nHere it comes!\nOh no...\nSomething happened\n")
|
| ... | ... |
@@ -182,10 +182,8 @@ func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engin |
| 182 | 182 |
} |
| 183 | 183 |
} |
| 184 | 184 |
os.MkdirAll(root, 0700) |
| 185 |
- eng, err := engine.New() |
|
| 186 |
- if err != nil {
|
|
| 187 |
- t.Fatal(err) |
|
| 188 |
- } |
|
| 185 |
+ |
|
| 186 |
+ eng := engine.New() |
|
| 189 | 187 |
// Load default plugins |
| 190 | 188 |
builtins.Register(eng) |
| 191 | 189 |
// (This is manually copied and modified from main() until we have a more generic plugin system) |