Browse code

Engine: add tests for ParseJob()

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)

Solomon Hykes authored on 2014/02/25 05:06:08
Showing 1 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"os"
6 6
 	"path"
7 7
 	"path/filepath"
8
+	"strings"
8 9
 	"testing"
9 10
 )
10 11
 
... ...
@@ -114,3 +115,40 @@ func TestEngineLogf(t *testing.T) {
114 114
 		t.Fatalf("Test: Logf() should print at least as much as the input\ninput=%d\nprinted=%d", len(input), n)
115 115
 	}
116 116
 }
117
+
118
+func TestParseJob(t *testing.T) {
119
+	eng := newTestEngine(t)
120
+	defer os.RemoveAll(eng.Root())
121
+	// Verify that the resulting job calls to the right place
122
+	var called bool
123
+	eng.Register("echo", func(job *Job) Status {
124
+		called = true
125
+		return StatusOK
126
+	})
127
+	input := "echo DEBUG=1 hello world VERBOSITY=42"
128
+	job, err := eng.ParseJob(input)
129
+	if err != nil {
130
+		t.Fatal(err)
131
+	}
132
+	if job.Name != "echo" {
133
+		t.Fatalf("Invalid job name: %v", job.Name)
134
+	}
135
+	if strings.Join(job.Args, ":::") != "hello:::world" {
136
+		t.Fatalf("Invalid job args: %v", job.Args)
137
+	}
138
+	if job.Env().Get("DEBUG") != "1" {
139
+		t.Fatalf("Invalid job env: %v", job.Env)
140
+	}
141
+	if job.Env().Get("VERBOSITY") != "42" {
142
+		t.Fatalf("Invalid job env: %v", job.Env)
143
+	}
144
+	if len(job.Env().Map()) != 2 {
145
+		t.Fatalf("Invalid job env: %v", job.Env)
146
+	}
147
+	if err := job.Run(); err != nil {
148
+		t.Fatal(err)
149
+	}
150
+	if !called {
151
+		t.Fatalf("Job was not called")
152
+	}
153
+}