Files
containerd/core/mount/manager_test.go
T
Derek McGowan 00967ecf03 mount: add WithAllowTransform activate option
A caller that applies a mount transform itself had to say so by naming the
mount type "format/*", a sentinel the mount manager constructs internally
by concatenating a transform name with "/*". Both sides had to
independently know and agree on that convention, and the resulting string
is neither a mount type nor a transform name.

Add AllowTransforms, and WithAllowTransform to set it, so a transform can
be claimed by its own name instead. The "/*" convention is removed rather
than kept as a second accepted spelling: it existed only to be produced by
the runtime-allow-mounts annotation, which is removed in an earlier commit
in this series, and there is no other producer of it in this tree.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-08-26 10:49:00 -07:00

51 lines
1.4 KiB
Go

/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package mount
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWithAllowMountType(t *testing.T) {
var o ActivateOptions
WithAllowMountType("erofs")(&o)
WithAllowMountType("loop")(&o)
assert.Equal(t, []string{"erofs", "loop"}, o.AllowMountTypes)
assert.Empty(t, o.AllowTransforms)
}
func TestWithAllowTransform(t *testing.T) {
var o ActivateOptions
WithAllowTransform("format")(&o)
WithAllowTransform("mkfs")(&o)
assert.Equal(t, []string{"format", "mkfs"}, o.AllowTransforms)
assert.Empty(t, o.AllowMountTypes)
}
func TestWithAllowMountTypeAndTransformCombine(t *testing.T) {
var o ActivateOptions
WithAllowMountType("block")(&o)
WithAllowTransform("format")(&o)
assert.Equal(t, []string{"block"}, o.AllowMountTypes)
assert.Equal(t, []string{"format"}, o.AllowTransforms)
}