Skip to content

Commit

Permalink
Merge pull request #4315 from shykes/engine-parsejob-test
Browse files Browse the repository at this point in the history
Engine: add tests for ParseJob()
  • Loading branch information
vieux committed Feb 24, 2014
2 parents 88b774d + 0469e7d commit ad88d0b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"testing"
)

Expand Down Expand Up @@ -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")
}
}
2 changes: 1 addition & 1 deletion engine/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (env *Env) Exists(key string) bool {
}

func (env *Env) Init(src *Env) {
*env = make([]string, 0, len(*src))
(*env) = make([]string, 0, len(*src))
for _, val := range *src {
(*env) = append((*env), val)
}
Expand Down

0 comments on commit ad88d0b

Please sign in to comment.