From 490c9b8e6f823cda4fb9344dd283af4ba2d82a54 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Sat, 28 Mar 2020 17:05:30 +0300 Subject: [PATCH] Test source files. --- distbuild/disttest/single_worker_test.go | 32 +++++++++++++++++-- .../disttest/testdata/TestSourceFiles/a.txt | 1 + .../disttest/testdata/TestSourceFiles/b/c.txt | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 distbuild/disttest/testdata/TestSourceFiles/a.txt create mode 100644 distbuild/disttest/testdata/TestSourceFiles/b/c.txt diff --git a/distbuild/disttest/single_worker_test.go b/distbuild/disttest/single_worker_test.go index 35cb6bc..0c2b1e2 100644 --- a/distbuild/disttest/single_worker_test.go +++ b/distbuild/disttest/single_worker_test.go @@ -67,6 +67,34 @@ func TestJobCaching(t *testing.T) { require.Equal(t, []byte("OK\n"), output) } -func TestSourceFiles(t *testing.T) { - +var sourceFilesGraph = build.Graph{ + SourceFiles: map[build.ID]string{ + build.ID{'a'}: "a.txt", + build.ID{'c'}: "b/c.txt", + }, + Jobs: []build.Job{ + { + ID: build.ID{'a'}, + Name: "echo", + Cmds: []build.Cmd{ + {Exec: []string{"cat", "{{.SourceDir}}/a.txt"}}, + {Exec: []string{"bash", "-c", "cat {{.SourceDir}}/b/c.txt > /dev/stderr"}}, + }, + Inputs: []string{ + "a.txt", + "b/c.txt", + }, + }, + }, +} + +func TestSourceFiles(t *testing.T) { + env, cancel := newEnv(t) + defer cancel() + + recorder := NewRecorder() + require.NoError(t, env.Client.Build(env.Ctx, sourceFilesGraph, recorder)) + + assert.Len(t, recorder.Jobs, 1) + assert.Equal(t, &JobResult{Stdout: "foo", Stderr: "bar", Code: new(int)}, recorder.Jobs[build.ID{'a'}]) } diff --git a/distbuild/disttest/testdata/TestSourceFiles/a.txt b/distbuild/disttest/testdata/TestSourceFiles/a.txt new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/distbuild/disttest/testdata/TestSourceFiles/a.txt @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/distbuild/disttest/testdata/TestSourceFiles/b/c.txt b/distbuild/disttest/testdata/TestSourceFiles/b/c.txt new file mode 100644 index 0000000..ba0e162 --- /dev/null +++ b/distbuild/disttest/testdata/TestSourceFiles/b/c.txt @@ -0,0 +1 @@ +bar \ No newline at end of file