1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/engine/utils/foreach_test.go
Vishal Choudhary 3af0e461f0
fix: deepcopy patched resource in foreach mutate (#10252)
* fix: deepcopy patched resource to avoid indirect reversal of its elements

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix: copy elements while reversing

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix: copy resources inside foreach

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* add test

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* add test

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

---------

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
Signed-off-by: Jim Bugwadia <jim@nirmata.com>
Co-authored-by: Jim Bugwadia <jim@nirmata.com>
2024-05-20 14:45:21 +08:00

16 lines
320 B
Go

package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_InvertElements(t *testing.T) {
elems := []interface{}{"a", "b", "c"}
elemsInverted := InvertElements(elems)
assert.Equal(t, "a", elemsInverted[2])
assert.Equal(t, "b", elemsInverted[1])
assert.Equal(t, "c", elemsInverted[0])
}