mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

The linter ensures a common code style. - use switch/case instead of else if - use if instead of switch/case for single case statement - add space between comment and text - detect the use of defer with os.Exit() - use short form var += "..." instead of var = var + "..." - detect problems with append() ``` newSlice := append(orgSlice, val) ``` This could lead to nasty bugs because the orgSlice will be changed in place if it has enough capacity too hold the new elements. Thus we newSlice might not be a copy. Of course most of the changes are just cosmetic and do not cause any logic errors but I think it is a good idea to enforce a common style. This should help maintainability. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package kube
|
|
|
|
import (
|
|
"testing"
|
|
|
|
v1 "github.com/containers/podman/v4/pkg/k8s.io/api/core/v1"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func testPropagation(t *testing.T, propagation v1.MountPropagationMode, expected string) {
|
|
dest, options, err := parseMountPath("/to", false, &propagation)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, dest, "/to")
|
|
assert.Contains(t, options, expected)
|
|
}
|
|
|
|
func TestParseMountPathPropagation(t *testing.T) {
|
|
testPropagation(t, v1.MountPropagationNone, "private")
|
|
testPropagation(t, v1.MountPropagationHostToContainer, "rslave")
|
|
testPropagation(t, v1.MountPropagationBidirectional, "rshared")
|
|
|
|
prop := v1.MountPropagationMode("SpaceWave")
|
|
_, _, err := parseMountPath("/to", false, &prop)
|
|
assert.Error(t, err)
|
|
|
|
_, options, err := parseMountPath("/to", false, nil)
|
|
assert.NoError(t, err)
|
|
assert.NotContains(t, options, "private")
|
|
assert.NotContains(t, options, "rslave")
|
|
assert.NotContains(t, options, "rshared")
|
|
}
|
|
|
|
func TestParseMountPathRO(t *testing.T) {
|
|
_, options, err := parseMountPath("/to", true, nil)
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, options, "ro")
|
|
|
|
_, options, err = parseMountPath("/to", false, nil)
|
|
assert.NoError(t, err)
|
|
assert.NotContains(t, options, "ro")
|
|
}
|