mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Engine: add tests for ParseJob()
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
05e4030313
commit
d985fd4984
1 changed files with 38 additions and 0 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -114,3 +115,40 @@ func TestEngineLogf(t *testing.T) {
|
|||
t.Fatalf("Test: Logf() should print at least as much as the input\ninput=%d\nprinted=%d", len(input), n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseJob(t *testing.T) {
|
||||
eng := newTestEngine(t)
|
||||
defer os.RemoveAll(eng.Root())
|
||||
// Verify that the resulting job calls to the right place
|
||||
var called bool
|
||||
eng.Register("echo", func(job *Job) Status {
|
||||
called = true
|
||||
return StatusOK
|
||||
})
|
||||
input := "echo DEBUG=1 hello world VERBOSITY=42"
|
||||
job, err := eng.ParseJob(input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job.Name != "echo" {
|
||||
t.Fatalf("Invalid job name: %v", job.Name)
|
||||
}
|
||||
if strings.Join(job.Args, ":::") != "hello:::world" {
|
||||
t.Fatalf("Invalid job args: %v", job.Args)
|
||||
}
|
||||
if job.Env().Get("DEBUG") != "1" {
|
||||
t.Fatalf("Invalid job env: %v", job.Env)
|
||||
}
|
||||
if job.Env().Get("VERBOSITY") != "42" {
|
||||
t.Fatalf("Invalid job env: %v", job.Env)
|
||||
}
|
||||
if len(job.Env().Map()) != 2 {
|
||||
t.Fatalf("Invalid job env: %v", job.Env)
|
||||
}
|
||||
if err := job.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !called {
|
||||
t.Fatalf("Job was not called")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue