From 05846d1485e670944527b2d4a90c2588065ad0e3 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 3f2c64bc6..b8f2fe5b1 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()