add unit test for getmount output index

Signed-off-by: Cory Bennett <cbennett@netflix.com>
This commit is contained in:
Cory Bennett
2020-06-04 18:16:59 -07:00
parent f720548416
commit e351bfdd01

View File

@@ -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")
}