|
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 | 115 | t.Fatalf("Test: Logf() should print at least as much as the input\ninput=%d\nprinted=%d", len(input), n) |
115 | 116 | } |
116 | 117 | } |
| 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 | +} |
0 commit comments