Artifact transfer

This commit is contained in:
Fedor Korotkiy 2020-03-28 17:22:24 +03:00
parent 490c9b8e6f
commit d3f089aaf4
2 changed files with 35 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package disttest
import (
"fmt"
"io/ioutil"
"testing"
@ -69,8 +70,8 @@ func TestJobCaching(t *testing.T) {
var sourceFilesGraph = build.Graph{
SourceFiles: map[build.ID]string{
build.ID{'a'}: "a.txt",
build.ID{'c'}: "b/c.txt",
{'a'}: "a.txt",
{'c'}: "b/c.txt",
},
Jobs: []build.Job{
{
@ -98,3 +99,34 @@ func TestSourceFiles(t *testing.T) {
assert.Len(t, recorder.Jobs, 1)
assert.Equal(t, &JobResult{Stdout: "foo", Stderr: "bar", Code: new(int)}, recorder.Jobs[build.ID{'a'}])
}
var artifactTransferGraph = build.Graph{
Jobs: []build.Job{
{
ID: build.ID{'a'},
Name: "write",
Cmds: []build.Cmd{
{CatTemplate: "OK", CatOutput: "{{.OutputDir}}/out.txt"},
},
},
{
ID: build.ID{'b'},
Name: "cat",
Cmds: []build.Cmd{
{Exec: []string{"cat", fmt.Sprintf("{{index .Deps %q}}/out.txt", build.ID{'a'})}},
},
Deps: []build.ID{{'a'}},
},
},
}
func TestArtifactTransfer(t *testing.T) {
env, cancel := newEnv(t)
defer cancel()
recorder := NewRecorder()
require.NoError(t, env.Client.Build(env.Ctx, artifactTransferGraph, recorder))
assert.Len(t, recorder.Jobs, 2)
assert.Equal(t, &JobResult{Stdout: "OK", Code: new(int)}, recorder.Jobs[build.ID{'b'}])
}

View file

@ -119,7 +119,7 @@ func (w *Worker) Run(ctx context.Context) error {
for _, spec := range rsp.JobsToRun {
result, err := w.runJob(ctx, &spec)
if err != nil {
errStr := err.Error()
errStr := fmt.Sprintf("job %s failed: %v", spec.Job.ID, err)
w.jobFinished(&proto.JobResult{ID: spec.Job.ID, Error: &errStr})
continue
}