Skip to content

Commit fb0b282

Browse files
mdryaancmainas
authored andcommitted
fix(unikontainers): preserve slice order when removing element
Signed-off-by: mdryaan <alikhurshid842001@gmail.com>
1 parent 3f8ae50 commit fb0b282

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

pkg/unikontainers/utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ func handleQueueProxy(spec specs.Spec, configFile string) error {
164164
}
165165

166166
func remove(s []string, i int) []string {
167-
s[i] = s[len(s)-1]
168-
return s[:len(s)-1]
167+
return append(s[:i], s[i+1:]...)
169168
}
170169

171170
func checkValidNsPath(path string) error {

pkg/unikontainers/utils_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ func TestMoveFile(t *testing.T) {
234234
})
235235
}
236236

237+
func TestRemovePreservesOrder(t *testing.T) {
238+
t.Parallel()
239+
result := remove([]string{"a", "b", "c", "d"}, 0)
240+
assert.Equal(t, []string{"b", "c", "d"}, result)
241+
}
242+
237243
func TestLoadSpec(t *testing.T) {
238244
t.Run("load spec success", func(t *testing.T) {
239245
t.Parallel()

0 commit comments

Comments
 (0)