Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Apr 15, 2024
1 parent 2800929 commit aeff59e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ func (d *DockerRuntime) initWorkDir(ctx context.Context, containerID string, t *
}()

for filename, contents := range t.Files {
ar.WriteFile(filename, 0444, []byte(contents))
if err := ar.WriteFile(filename, 0444, []byte(contents)); err != nil {
return err
}
}

if err := d.client.CopyToContainer(ctx, containerID, t.Workdir, ar, types.CopyToContainerOptions{}); err != nil {
Expand Down
42 changes: 42 additions & 0 deletions runtime/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ func TestRunTaskWithVolume(t *testing.T) {
assert.NoError(t, err)
}

func TestRunTaskWithVolumeAndCustomWorkdir(t *testing.T) {
rt, err := NewDockerRuntime()
assert.NoError(t, err)

ctx := context.Background()

t1 := &tork.Task{
ID: uuid.NewUUID(),
Image: "ubuntu:mantic",
Run: `echo hello world > /xyz/thing
ls > $TORK_OUTPUT`,
Mounts: []tork.Mount{
{
Type: tork.MountTypeVolume,
Target: "/xyz",
},
},
Workdir: "/xyz",
}
err = rt.Run(ctx, t1)
assert.NoError(t, err)
assert.Equal(t, "thing\n", t1.Result)
}

func TestRunTaskWithBind(t *testing.T) {
mm := runtime.NewMultiMounter()
vm, err := NewVolumeMounter()
Expand Down Expand Up @@ -390,6 +414,24 @@ func TestRunTaskInitWorkdir(t *testing.T) {
assert.Equal(t, "hello world", t1.Result)
}

func TestRunTaskInitWorkdirLs(t *testing.T) {
rt, err := NewDockerRuntime()
assert.NoError(t, err)
t1 := &tork.Task{
ID: uuid.NewUUID(),
Image: "ubuntu:mantic",
Run: "ls > $TORK_OUTPUT",
Files: map[string]string{
"hello.txt": "hello world",
"large.txt": strings.Repeat("a", 100_000),
},
}
ctx := context.Background()
err = rt.Run(ctx, t1)
assert.NoError(t, err)
assert.Equal(t, "hello.txt\nlarge.txt\n", t1.Result)
}

func TestRunTaskWithCustomMounter(t *testing.T) {
mounter := runtime.NewMultiMounter()
vmounter, err := NewVolumeMounter()
Expand Down

0 comments on commit aeff59e

Please sign in to comment.