Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad88d0b

Browse files
committed
Merge pull request moby#4315 from shykes/engine-parsejob-test
Engine: add tests for ParseJob()
2 parents 88b774d + 0469e7d commit ad88d0b

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

engine/engine_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path"
77
"path/filepath"
8+
"strings"
89
"testing"
910
)
1011

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

engine/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (env *Env) Exists(key string) bool {
3737
}
3838

3939
func (env *Env) Init(src *Env) {
40-
*env = make([]string, 0, len(*src))
40+
(*env) = make([]string, 0, len(*src))
4141
for _, val := range *src {
4242
(*env) = append((*env), val)
4343
}

0 commit comments

Comments
 (0)