diff options
Diffstat (limited to 'docker')
-rw-r--r-- | docker/instructions.go | 7 | ||||
-rw-r--r-- | docker/instructions_test.go | 22 |
2 files changed, 23 insertions, 6 deletions
diff --git a/docker/instructions.go b/docker/instructions.go index 8463b0e..56c04b9 100644 --- a/docker/instructions.go +++ b/docker/instructions.go @@ -26,7 +26,12 @@ func NewInstruction(bi build.Instruction) (Instruction, error) { switch bi.(type) { case build.CopyAs: - i.flags = []string{"chown"} + switch bi.(build.CopyAs).Instruction.(type) { + case build.Copy: + i.flags = []string{"chown"} + case build.CopyFrom: + i.flags = []string{"chown", "from"} + } case build.CopyFrom: i.flags = []string{"from"} } diff --git a/docker/instructions_test.go b/docker/instructions_test.go index 6215841..07b71c7 100644 --- a/docker/instructions_test.go +++ b/docker/instructions_test.go @@ -42,13 +42,25 @@ func TestCopy(t *testing.T) { } func TestCopyAs(t *testing.T) { - i := build.CopyAs{123, 124, build.Copy{[]string{"foo1", "foo2"}, "bar"}} + t.Run("with Copy", func(t *testing.T) { + i := build.CopyAs{123, 124, build.Copy{[]string{"foo1", "foo2"}, "bar"}} - di, err := docker.NewInstruction(i) + di, err := docker.NewInstruction(i) - if assert.NoError(t, err) { - assert.Equal(t, "COPY --chown=123:124 [\"foo1\", \"foo2\", \"bar\"]\n", di.Compile()) - } + if assert.NoError(t, err) { + assert.Equal(t, "COPY --chown=123:124 [\"foo1\", \"foo2\", \"bar\"]\n", di.Compile()) + } + }) + + t.Run("with CopyFrom", func(t *testing.T) { + i := build.CopyAs{123, 124, build.CopyFrom{"foo", build.Copy{[]string{"foo1", "foo2"}, "bar"}}} + + di, err := docker.NewInstruction(i) + + if assert.NoError(t, err) { + assert.Equal(t, "COPY --chown=123:124 --from=foo [\"foo1\", \"foo2\", \"bar\"]\n", di.Compile()) + } + }) } func TestCopyFrom(t *testing.T) { |