From 5a99b19e298853d15f91a3a0f78e21fb13c28d71 Mon Sep 17 00:00:00 2001 From: mdryaan Date: Thu, 14 May 2026 08:57:26 +0530 Subject: [PATCH] fix(unikontainers): preserve slice order when removing element Signed-off-by: mdryaan --- pkg/unikontainers/utils.go | 3 +-- pkg/unikontainers/utils_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/unikontainers/utils.go b/pkg/unikontainers/utils.go index c53c0fc05..dd9fd0b58 100644 --- a/pkg/unikontainers/utils.go +++ b/pkg/unikontainers/utils.go @@ -164,8 +164,7 @@ func handleQueueProxy(spec specs.Spec, configFile string) error { } func remove(s []string, i int) []string { - s[i] = s[len(s)-1] - return s[:len(s)-1] + return append(s[:i], s[i+1:]...) } func checkValidNsPath(path string) error { diff --git a/pkg/unikontainers/utils_test.go b/pkg/unikontainers/utils_test.go index a78522fa0..b779b982e 100644 --- a/pkg/unikontainers/utils_test.go +++ b/pkg/unikontainers/utils_test.go @@ -234,6 +234,12 @@ func TestMoveFile(t *testing.T) { }) } +func TestRemovePreservesOrder(t *testing.T) { + t.Parallel() + result := remove([]string{"a", "b", "c", "d"}, 0) + assert.Equal(t, []string{"b", "c", "d"}, result) +} + func TestLoadSpec(t *testing.T) { t.Run("load spec success", func(t *testing.T) { t.Parallel()