Files
podman/libpod/util_test.go
Paul Holzinger 953e385bd2 libpod: fix mount order for "/" volume
The count function for / and /proc results in the same value so the
order is not guaranteed. We must ensure that a / mount is always first
in the spec so that other mounts are not overshadowed by it.

Fixes: #26161

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-05-20 15:52:27 +02:00

70 lines
994 B
Go

//go:build !remote
package libpod
import (
"testing"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
func Test_sortMounts(t *testing.T) {
tests := []struct {
name string
args []spec.Mount
want []spec.Mount
}{
{
name: "simple nested mounts",
args: []spec.Mount{
{
Destination: "/abc/123",
},
{
Destination: "/abc",
},
},
want: []spec.Mount{
{
Destination: "/abc",
},
{
Destination: "/abc/123",
},
},
},
{
name: "root mount",
args: []spec.Mount{
{
Destination: "/abc",
},
{
Destination: "/",
},
{
Destination: "/def",
},
},
want: []spec.Mount{
{
Destination: "/",
},
{
Destination: "/abc",
},
{
Destination: "/def",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := sortMounts(tt.args)
assert.Equal(t, tt.want, got)
})
}
}