mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
kublet/userns: Test error messages on init failures
This adds a test for the just added wrapping error message, as well as for the other already present error messages that initialization can fail with. Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
This commit is contained in:
parent
a56d483df0
commit
cae710d9e9
@ -18,6 +18,7 @@ package userns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -360,3 +361,38 @@ func TestRecordMaxPods(t *testing.T) {
|
|||||||
err = m.record(types.UID(fmt.Sprintf("%d", maxPods+1)), uint32((maxPods+1)*65536), 65536)
|
err = m.record(types.UID(fmt.Sprintf("%d", maxPods+1)), uint32((maxPods+1)*65536), 65536)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type failingUserNsPodsManager struct {
|
||||||
|
testUserNsPodsManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *failingUserNsPodsManager) ListPodsFromDisk() ([]types.UID, error) {
|
||||||
|
return nil, os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMakeUserNsManagerFailsListPod(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
||||||
|
|
||||||
|
testUserNsPodsManager := &failingUserNsPodsManager{}
|
||||||
|
_, err := MakeUserNsManager(testUserNsPodsManager)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorContains(t, err, "read pods from disk")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMakeUserNsManagerFailsPodRecord(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.UserNamespacesSupport, true)()
|
||||||
|
|
||||||
|
testUserNsPodsManager := &testUserNsPodsManager{
|
||||||
|
podList: []types.UID{"pod-1", "pod-2"},
|
||||||
|
podDir: t.TempDir(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove read/execute permissions from this directory.
|
||||||
|
if err := os.Chmod(testUserNsPodsManager.podDir, 0222); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := MakeUserNsManager(testUserNsPodsManager)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.ErrorContains(t, err, "record pod mappings")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user