1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package llb
import (
"context"
"testing"
"github.com/moby/buildkit/solver/pb"
"github.com/stretchr/testify/require"
)
func TestTmpfsMountError(t *testing.T) {
t.Parallel()
st := Image("foo").Run(Shlex("args")).AddMount("/tmp", Scratch(), Tmpfs())
_, err := st.Marshal(context.TODO())
require.Error(t, err)
require.Contains(t, err.Error(), "can't be used as a parent")
st = Image("foo").Run(Shlex("args"), AddMount("/tmp", Scratch(), Tmpfs())).Root()
_, err = st.Marshal(context.TODO())
require.NoError(t, err)
st = Image("foo").Run(Shlex("args"), AddMount("/tmp", Image("bar"), Tmpfs())).Root()
_, err = st.Marshal(context.TODO())
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")
}
|