diff --git a/pkg/unikontainers/utils.go b/pkg/unikontainers/utils.go index 3f2c64bc..b8f2fe5b 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 a78522fa..b779b982 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()