From e351bfdd017775ab872442d74ea2ea5aae837f69 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Thu, 4 Jun 2020 18:16:59 -0700 Subject: [PATCH] add unit test for getmount output index Signed-off-by: Cory Bennett --- client/llb/exec_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client/llb/exec_test.go b/client/llb/exec_test.go index 5ce3f0cbd..b9de052cb 100644 --- a/client/llb/exec_test.go +++ b/client/llb/exec_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + "github.com/moby/buildkit/solver/pb" "github.com/stretchr/testify/require" ) @@ -25,3 +26,27 @@ func TestTmpfsMountError(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "must use scratch") } + +func TestValidGetMountIndex(t *testing.T) { + // tests for https://github.com/moby/buildkit/issues/1520 + + // tmpfs mount /c will sort later than target mount /b, /b will have output index==1 + st := Image("foo").Run(Shlex("args"), AddMount("/b", Scratch()), AddMount("/c", Scratch(), Tmpfs())).GetMount("/b") + + mountOutput, ok := st.Output().(*output) + require.True(t, ok, "mount output is expected type") + + mountIndex, err := mountOutput.getIndex() + require.NoError(t, err, "failed to getIndex") + require.Equal(t, pb.OutputIndex(1), mountIndex, "unexpected mount index") + + // now swapping so the tmpfs mount /a will sort earlier than the target mount /b, /b should still have output index==1 + st = Image("foo").Run(Shlex("args"), AddMount("/b", Scratch()), AddMount("/a", Scratch(), Tmpfs())).GetMount("/b") + + mountOutput, ok = st.Output().(*output) + require.True(t, ok, "mount output is expected type") + + mountIndex, err = mountOutput.getIndex() + require.NoError(t, err, "failed to getIndex") + require.Equal(t, pb.OutputIndex(1), mountIndex, "unexpected mount index") +}